`
standalone
  • 浏览: 596600 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Java synchronized methods

    博客分类:
  • java
阅读更多

 

 

  • First, it is not possible for two invocations of synchronized methods on the same object to interleave. When one thread is executing a synchronized method for an object, all other threads that invoke synchronized methods for the same object block (suspend execution) until the first thread is done with the object.
  • Second, when a synchronized method exits, it automatically establishes a happens-before relationship with any subsequent invocation of a synchronized method for the same object. This guarantees that changes to the state of the object are visible to all threads.

在sun的tutorial上,对synchronized methods有上面的解释。意思是一个method加了这个关键字之后, 第一,多个线程不能同时执行同一个对象的synchronized方法,只能串行。第二,在一个synchronized方法执行完后,保证了对这个对象做的所有改动都对其他线程可见。

 

 

 

分享到:
评论

相关推荐

    深入java虚拟机(inside the java virtual machine)

    Synchronized Methods Coordination Support in Class Object On the CD-ROM The Resources Page Appendix A. Instructions by Opcode Mnemonic Appendix B. Opcode Mnemonic by Functional Group Appendix C. ...

    commons-httpclient-3.0.1--java网络开发

    import java.io.IOException; import org.apache.commons.httpclient.params.HttpClientParams; import org.apache.commons.logging.Log; public class HttpClient { // Fields private static final Log LOG; ...

    JAVA面试题最全集

    简述synchronized和java.util.concurrent.locks.Lock的异同 ? 34.EJB规范规定EJB中禁止的操作有哪些? 35.java除了8种基本类型外,在虚拟机里还有哪一种,有什么作用? 36.除了使用new关键字创建对象意外,试列举...

    java 面试题 总结

    换言之,很可能数个使用者在执行某个 Stateless Session Bean 的 methods 时,会是同一个 Bean 的 Instance 在执行。从内存方面来看, Stateful Session Bean 与 Stateless Session Bean 比较, Stateful Session ...

    Learn.Java.for.Android.Development_Apress.2010+src

    What you''ll learn The Java language: This book provides complete coverage of nearly every pre-Java version 7 language feature (native methods are briefly mentioned but not formally covered)....

    超级有影响力霸气的Java面试题大全文档

    换言之,很可能数个使用者在执行某个 Stateless Session Bean 的 methods 时,会是同一个 Bean 的 Instance 在执行。从内存方面来看, Stateful Session Bean 与 Stateless Session Bean 比较, Stateful Session ...

    关于JAVA面试的100题及其答案

    换言之,很可能数个使用者在执行某个 Stateless Session Bean 的 methods 时,会是同一个 Bean 的 Instance 在执行。从内存方面来看, Stateful Session Bean 与 Stateless Session Bean 比较, Stateful Session ...

    Programming Microsoft LINQ in Microsoft.NET Framework 4

    Check out the related LiveLessons video product, C# 2010 Fundamentals: Parts I, II and III, containing 20+ hours of video synchronized to this book: www.deitel.com/livelessons. Practical, example-...

    C# 2010 for Programmers 4ed part1

    Check out the related LiveLessons video product, C# 2010 Fundamentals: Parts I, II and III, containing 20+ hours of video synchronized to this book: www.deitel.com/livelessons. Practical, example-...

    ThreadTest:多线程

    Синхронизация ресурсов - блок кода "synchronized" Низкоуровневые блокировки Неблокирующие алгоритмы Java中的原子变量 ...

    sesvc.exe 阿萨德

    Java JavaScript PHP iOS Android HTML5 CSS3 Linux C++ Python C# Node.Js 一文让你彻底理解 Java HashMap 和 ConcurrentHashMap 2018-07-25 分类:JAVA开发、编程开发、首页精华0人评论 ...

    进销存系统文档作业例子

    换言之,很可能数个使用者在执行某个 Stateless Session Bean 的 methods 时,会是同一个 Bean 的 Instance 在执行。从内存方面来看, Stateful Session Bean 与 Stateless Session Bean 比较, Stateful Session ...

    python3.6.5参考手册 chm

    Deprecated Python modules, functions and methods asynchat asyncore dbm distutils grp importlib os re ssl tkinter venv Deprecated functions and types of the C API Deprecated Build Options ...

Global site tag (gtag.js) - Google Analytics