Synchronization is achieved using monitors. Every object can have a monitor associated with it, so any object can synchronize blocks. Before a synchronized block can be entered, a thread needs to gain ownership of the monitor for that block. Once the thread has gained ownership of the monitor, no other thread synchronized on the same monitor can gain entry to that block (or any other block or method synchronized on the same monitor). The thread owning the monitor gets to execute all the statements in the block, and then automatically releases ownership of the monitor on exiting the block. At that point, another thread waiting to enter the block can acquire ownership of the monitor.
黄小贝 发表于 2013-11-13 18:23
每一个对象都有一个监听器(monitor),每一个synchronizad()代码块的括号里面的都是一个对象, 当一个 ...
落木萧萧 发表于 2013-11-13 18:28
小贝童鞋对线程问题很上心啊
黄小贝 发表于 2013-11-13 18:36
那是,最近在怒看《java threads》,我的笔记~多多指教~
http://2925665.blog.51cto.com/2915665/131358 ...
落木萧萧 发表于 2013-11-13 18:45
翻译两字已经亮瞎我了
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |