Effective Java 73 Avoid thread groups】的更多相关文章

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…
Principle To avoid liveness and safety failures, never cede control to the client within a synchronized method or block. Do as little work as possible inside synchronized regions. You should make a mutable class thread-safe (Item 70) if it is intende…
Principle Strings are poor substitutes for other value types. Such as int, float or BigInteger. Strings are poor substitutes for enum types. As discussed in Item 30. Strings are poor substitutes for aggregate types. A better approach is simply to wri…
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 •…
NOTE Never do anything time-critical in a finalizer. Never depend on a finalizer to update critical persistent state. There is a severe performance penalty for using. "Finalizer chaining" is not performed automatically. The subclass finalizer mu…
String s = new String("stringette"); // Don't do this. This will create an object each time Vs String s = "stringette"; class Person { private final Date birthDate; // Other fields, methods, and constructor omitted /** * The starting a…
Reason The float and double types are particularly ill-suited for monetary calculations because it is impossible to represent 0.1 (or any other negative power of ten) as a float or double exactly. // This will print 0.6100000000000001 System.out.prin…
The burden is justified if the exceptional condition cannot be prevented by proper use of the API and the programmer using the API can take some useful action once confronted with the exception. ask yourself how the programmer will handle the excepti…
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…