草庐IT

thread-synchronization

全部标签

java - Thread.stop 和 friend 在 Java 中安全吗?

stop(),suspend(),和resume()在java.lang.Thread已弃用,因为它们是unsafe.Oracle推荐的解决方法是使用Thread.interrupt(),但这种方法并不适用于所有情况。例如,如果您调用的库方法没有显式或隐式检查interruptedflag,你别无选择,只能等待调用完成。所以,我想知道是否有可能描述调用stop()是(可证明)安全的情况。在一个线程上。例如,stop()是否安全?一个线程只调用find(...)或match(...)在java.util.regex.Matcher?(如果有任何Oracle工程师正在阅读这篇文章.....

java - Thread.stop 和 friend 在 Java 中安全吗?

stop(),suspend(),和resume()在java.lang.Thread已弃用,因为它们是unsafe.Oracle推荐的解决方法是使用Thread.interrupt(),但这种方法并不适用于所有情况。例如,如果您调用的库方法没有显式或隐式检查interruptedflag,你别无选择,只能等待调用完成。所以,我想知道是否有可能描述调用stop()是(可证明)安全的情况。在一个线程上。例如,stop()是否安全?一个线程只调用find(...)或match(...)在java.util.regex.Matcher?(如果有任何Oracle工程师正在阅读这篇文章.....

java - Thread.stop() - 已弃用

为什么在Java中不推荐使用Thread.stop()?在他们的网站上,我看到以下内容:WhyisThread.stopdeprecated?Becauseitisinherentlyunsafe.Stoppingathreadcausesittounlockallthemonitorsthatithaslocked.(ThemonitorsareunlockedastheThreadDeathexceptionpropagatesupthestack.)Ifanyoftheobjectspreviouslyprotectedbythesemonitorswereinaninconsi

java - Thread.stop() - 已弃用

为什么在Java中不推荐使用Thread.stop()?在他们的网站上,我看到以下内容:WhyisThread.stopdeprecated?Becauseitisinherentlyunsafe.Stoppingathreadcausesittounlockallthemonitorsthatithaslocked.(ThemonitorsareunlockedastheThreadDeathexceptionpropagatesupthestack.)Ifanyoftheobjectspreviouslyprotectedbythesemonitorswereinaninconsi

java - 与 Java 中的 volatile 字段和同步块(synchronized block)的关系——以及它们对非 volatile 变量的影响?

我对线程的概念仍然很陌生,并尝试更多地了解它。最近,我在WhatVolatileMeansinJava上看到了一篇博文。杰里米·曼森(JeremyManson)写道:Whenonethreadwritestoavolatilevariable,andanotherthreadseesthatwrite,thefirstthreadistellingthesecondaboutallofthecontentsofmemoryupuntilitperformedthewritetothatvolatilevariable.[...]allofthememorycontentsseenbyT

java - 与 Java 中的 volatile 字段和同步块(synchronized block)的关系——以及它们对非 volatile 变量的影响?

我对线程的概念仍然很陌生,并尝试更多地了解它。最近,我在WhatVolatileMeansinJava上看到了一篇博文。杰里米·曼森(JeremyManson)写道:Whenonethreadwritestoavolatilevariable,andanotherthreadseesthatwrite,thefirstthreadistellingthesecondaboutallofthecontentsofmemoryupuntilitperformedthewritetothatvolatilevariable.[...]allofthememorycontentsseenbyT

java - TimerTask vs Thread.sleep vs Handler postDelayed - 每N毫秒调用一次函数最准确?

每N毫秒调用一次函数最准确的方法是什么?带有Thread.sleep的线程定时器任务带有postDelayed的处理程序我修改了thisexample使用Thread.sleep并且不是很准确。我正在开发一个音乐应用程序,它将以给定的BPM播放声音。我知道创建一个完全准确的节拍器是不可能的,我也不需要-只是想找到最好的方法来做到这一点。谢谢 最佳答案 使用定时器有一些缺点它只创建一个线程来执行任务,如果一个任务运行时间太长,其他任务会受到影响。它不处理任务和线程抛出的异常只是终止,这会影响其他计划任务,它们从不运行Scheduled

java - TimerTask vs Thread.sleep vs Handler postDelayed - 每N毫秒调用一次函数最准确?

每N毫秒调用一次函数最准确的方法是什么?带有Thread.sleep的线程定时器任务带有postDelayed的处理程序我修改了thisexample使用Thread.sleep并且不是很准确。我正在开发一个音乐应用程序,它将以给定的BPM播放声音。我知道创建一个完全准确的节拍器是不可能的,我也不需要-只是想找到最好的方法来做到这一点。谢谢 最佳答案 使用定时器有一些缺点它只创建一个线程来执行任务,如果一个任务运行时间太长,其他任务会受到影响。它不处理任务和线程抛出的异常只是终止,这会影响其他计划任务,它们从不运行Scheduled

Java Event-Dispatching Thread 解释

我最近开始学习和探索Java中GUI编程的基础知识。已经编程了一段时间,我只做过后端工作或工作,因此我最接近用户界面的是命令控制台(我知道很尴尬)。我正在使用Swing,据我所知,通过扩展,我也在使用AWT。我的问题是基于这段代码:java.awt.EventQueue.invokeLater(newRunnable(){publicvoidrun(){newframe.setVisible(true);}});我已经研究了一段时间,因为我想完全理解这段奇怪的代码,并且多次遇到“事件调度线程”这个术语。如果我错了,请纠正我,但据我所知;它与使用多个线程以及JavaSwing如何解释这些

Java Event-Dispatching Thread 解释

我最近开始学习和探索Java中GUI编程的基础知识。已经编程了一段时间,我只做过后端工作或工作,因此我最接近用户界面的是命令控制台(我知道很尴尬)。我正在使用Swing,据我所知,通过扩展,我也在使用AWT。我的问题是基于这段代码:java.awt.EventQueue.invokeLater(newRunnable(){publicvoidrun(){newframe.setVisible(true);}});我已经研究了一段时间,因为我想完全理解这段奇怪的代码,并且多次遇到“事件调度线程”这个术语。如果我错了,请纠正我,但据我所知;它与使用多个线程以及JavaSwing如何解释这些