Effective Java 70 Document thread safety】的更多相关文章

Principle The presence of the synchronized modifier in a method declaration is an implementation detail, not a part of its exported API. To enable safe concurrent use, a class must clearly document what level of thread safety it supports. Immutable •…
Principle Always declare checked exceptions individually, and document precisely the conditions under which each one is thrown using the Javadoc @throws tag. A well-documented list of the unchecked exceptions that a method can throw effectively descr…
Thread groups were originally envisioned as a mechanism for isolating applets for security purposes. They never really fulfilled this promise, and their security importance has waned to the extent that they aren't even mentioned in the standard work…
Hi guys, I am happy to tell you that I am moving to the open source world. And Java is the 1st language I have chosen for this migration. It's a nice chance to read some great books like "Effective Java 2nd Edition" and share the note for what I…
Chapter 10 Concurrency Item 66: Synchronize access to shared mutable data synchronized这个关键字不仅保证了同步,还保证了可见性(visibility). 对于变量的读写是原子性的,除非变量类型是long或double.有一个我见过无数遍的例子就是设一个共享的boolean变量,然后从一个线程中断另一个线程的while循环.因为JVM会做优化,但它做优化的前提是假设下面这些代码都是在单线程下运行的,比如可能把wh…
<Effective Java>目录摘抄. 我知道这看起来很糟糕.当下,自己缺少实际操作,只能暂时摘抄下目录.随着,实践的增多,慢慢填充更多的示例. Chapter 2 Creating and Destroying Objects Consider static factory methods instead of constructors Consider a builder when faced with many constructor parameters Enforce the s…
Java写了很多年,很惭愧,直到最近才读了这本经典之作<Effective Java>,按自己的理解总结下,有些可能还不够深刻 一.Creating and Destroying Objects Consider static factory methods instead of constructors (factory方法可以拥有名称,可以避免重复创建,比如单例模式) Consider a builder when faced with many constructor parameter…
Writing thread-safe code is managing access to state and in particular to shared, mutable state. Object's state is its data, stored in state variables such as instance or static fields. Whether an object needs to be thread-safe depends on whether it…
Thread Safety in Java is a very important topic. Java provide multi-threaded environment support using Java Threads, we know that multiple threads created from same Object share object variables and this can lead to data inconsistency when the thread…
Principle You must precede every exported class, interface, constructor, method, and field declaration with a doc comment. If a class is serializable, you should also document its serialized form (Item 75). To write maintainable code, you should also…