- 浏览: 748030 次
- 性别:
- 来自: 上海
-
文章分类
- 全部博客 (419)
- 杂软粉墨 (2)
- 创意灵感 (3)
- 经验记录 (137)
- 开源轨迹 (2)
- sip-communicator (2)
- 闲侃杂谈 (8)
- 问题交流 (24)
- 概念模式 (32)
- 难点备案 (5)
- JwChat (1)
- 中国象棋 (1)
- 教育探索 (6)
- 英语研究 (58)
- 星际争霸 (1)
- 电信知识 (1)
- 软件架构 (3)
- 哲学探索 (26)
- 算法灵魂 (8)
- 近视探索 (6)
- 数学数学 (3)
- 牛角钻尖 (23)
- 至强文言 (3)
- 数据结构 (1)
- 宇宙物理 (2)
- 网络架构 (3)
- 游戏领域 (4)
- 图形处理 (2)
- 修炼之路 (8)
- 读书天地 (20)
- 编解乱码 (2)
- 概念探索 (8)
- 格物致知 (1)
- 其它语言 (1)
- 测试领域 (3)
- 文化风流 (1)
- JQuery (1)
- 網頁領域 (1)
- Unix/Linux (1)
- Inside JVM (1)
- 异常分析 (1)
最新评论
-
suyujie:
引用
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
iamzhoug37:
您能说一下"局部变量不受文本顺序限制" 是 ...
声明前为什么能赋值却不能输出,都是使用
import java.util.Timer; import java.util.TimerTask; public class Worker extends Thread { private volatile boolean quittingTime = false; public void run() { while (!quittingTime) pretendToWork(); System.out.println("Beer is good"); } private void pretendToWork() { try { Thread.sleep(300); // Sleeping on the job? } catch (InterruptedException ex) { } } // It's quitting time, wait for worker - Called by good boss synchronized void quit() throws InterruptedException { quittingTime = true; join(); } // Rescind quitting time - Called by evil boss synchronized void keepWorking() { quittingTime = false; } public static void main(String[] args) throws InterruptedException { final Worker worker = new Worker(); worker.start(); Timer t = new Timer(true); // Daemon thread t.schedule(new TimerTask() { public void run() { worker.keepWorking(); } }, 500); Thread.sleep(400); worker.quit(); } }
If you run the above code, the program just hangs repeatably. why? anwser is located in Java Puzzlers puzzle 77 The Lock Mess Monster. as join method executed in the main thread just waits and releases the lock, the daemon thread accquires the lock and set it to run forever.
The answer concerns the implementation of Thread.join . It can't be found in the documentation for this method, at least in releases up to and including release 5.0. Internally, Thread.join calls Object.wait on the Thread instance representing the thread being joined. This releases the lock for the duration of the wait. In the case of our program, this allows the timer thread, representing the evil boss, to waltz in and set quittingTime back to false , even though the main thread is currently executing the synchronized quit method. As a consequence, the worker thread never sees that it's quitting time and keeps running forever. The main thread, representing the good boss, never returns from the join method.
here, i think the join method though executed by the main thread, and it waits for the main thread to die, but main thread wont go to death until the worker thread finishes its life, is it?
发表评论
-
NullPointerException in ternary operator
2013-01-19 00:01 1125java代码: Integer i = null; ... -
why concrete class must implement abstract method while abstract class need not
2011-05-11 13:27 1516yes, just as the title...why co ... -
Enum singleton - Elvis Stealer
2011-04-26 14:41 1636import java.io.ByteArrayInputSt ... -
why can inner class be instantiated in this way?
2011-04-06 10:24 1021public class Outer { pub ... -
into native source code
2011-03-23 23:09 965once there was a problem occurr ... -
why is static inner class singleton thread safe?
2011-03-15 09:03 1457http://en.wikipedia.org/wiki/In ... -
why string concatenation yields no interned one
2011-03-14 16:48 1114public class Test { public st ... -
why can bit mask suppress sign extention
2011-03-10 09:16 1181yes, bit mask can suppress sign ... -
About gc two objects which are inter referenced to each other
2011-03-08 11:00 1053my workmate told me such a sena ... -
circumvents exception checking
2011-03-03 11:02 968import java.io.IOException; ... -
关于维基中singleton pattern的一段
2011-02-24 10:00 1093Another notable difference is t ... -
why List hasn't clone method but the ArrayList has
2011-02-16 15:27 1172List list = new ArrayList(); ... -
deep copy
2011-02-16 15:20 1041static public Object deepCopy(O ... -
Java is Pass-by-Value
2011-02-14 13:28 1095This often heard saying is not ... -
不是说字符串不可变吗
2011-02-14 11:28 898from csdn: http://topic.csdn.ne ... -
没有实现抽象方法的具体类居然编译通过了
2011-02-04 22:29 976来自csdn: http://topic.csdn.net/ ... -
关于iterator的fail-fast
2011-01-20 11:15 997是使用集合的iterator后,再改变就可能抛出这个异常 ... -
生成几个String的问题
2011-01-11 16:26 1012public class Test extends java. ... -
无符号右移>>>
2011-01-11 15:46 2344public class Test { public st ... -
Struts2之log信息不出的问题
2010-12-30 11:18 3024刚开始学习Struts2的时候,用的是maven方式,但是却不 ...
相关推荐
AboutView.vue
All about AutoFilter.xlt
about Eason.html.mno
标题中的"PSO2.rar_About Method_s method_swarm"提到了“粒子群优化法”(Particle Swarm Optimization, PSO),这是一种基于群体智能的优化算法,由James Kennedy和Russell E. Eberhart在1995年提出。该算法模拟了...
this code is about the error control coding using matlabcode.the method that i used is convolution coding .
The basics about SLAM.pptx,经典资源
droid at school, useful to capture android screen shot
关于AboutTime时间校对工具,这是一款专用于网络时间同步的软件,它的主要功能是帮助用户确保计算机系统的时间准确无误。在计算机领域,时间的准确性对于许多应用和服务至关重要,例如金融交易、日志记录、分布式...
About_method.help.txt About_pssnapins.help.txt About_namespace.help.txt About_object.help.txt About_operator.help.txt About_parameter.help.txt About_parsing.help.txt About_path_syntax.help.txt About_...
本篇文章将深入解析如何在Windows系统中调用标准的ABOUT对话框,这一技术对于提升用户界面的友好性和软件的专业性具有显著作用。通过分析给定文件中的代码片段,我们将了解其工作原理,以及如何在自己的项目中应用这...
sap press doc 解压密码:abap_developer
"All About PDF 3.2000" 是一个针对PDF文件处理的软件工具,提供了全面的PDF管理功能,如PDF合并、拆分、转换以及加密等。 PDF合并功能允许用户将多个PDF文件整合到一个单一的文档中,这对于整理报告、论文或者手册...
Attribouter is a lightweight "about screen" for Android apps, built to allow developers to easily give credit to a project's contributors and open source libraries, while matching the style of their ...
现在很多人都用word写文档,调格式很麻烦,用Typora,不会用,我就用Typora整理了Markdown的语法供大家参考
Sourcegraph about.sourcegraph.com网站 使用Gatsby渲染由Netlify构建和部署的静态站点。 快速开始 什么 命令 自动预览about.sourcegraph.com cd website && yarn install && yarn start 最终评论about....
1. **微分方程的数值解法**:数值方法处理微分方程时,常用的方法有欧拉法(Euler's method)、龙格-库塔法(Runge-Kutta methods)以及有限差分法。这些方法通过近似连续函数的导数来离散化微分方程,然后求解得到...
关于在线名片网站about.me,其简约设计是其在竞争激烈的市场中脱颖而出的关键。about.me作为一个在线展示个人信息的平台,允许用户自定义个性化页面,包括个人简介、联系方式、社交媒体链接等,通过调整个人照片和...
All About CAPTCHA’s. This eBook will teach you how to identify weaknesses and exploit CAPTCHA’s from beginning to end. Welcome to the practical guide to decoding CAPTCHA's. Everything you need to ...
VC++ Custom Controls控件添加后可以编译通过但是运行不显示,删除控件后OK的问题的解决办法