11 Quotes by Brian Goetz about Java
- Author Brian Goetz
-
Quote
It is far easier to design a class to be thread-safe than to retrofit it for thread safety later.
- Tags
- Share
- Author Brian Goetz
-
Quote
Just as it is a good practice to make all fields private unless they need greater visibility, it is a good practice to make all fields final unless they need to be mutable.
- Tags
- Share
- Author Brian Goetz
-
Quote
Sometimes abstraction and encapsulation are at odds with performance — although not nearly as often as many developers believe — but it is always a good practice first to make your code right, and then make it fast.
- Tags
- Share
- Author Brian Goetz
-
Quote
Locking can guarantee both visibility and atomicity; volatile variables can only guarantee visibility.
- Tags
- Share
- Author Brian Goetz
-
Quote
Whenever more than one thread accesses a given state variable, and one of them might write to it, they all must coordinate their access to it using synchronization.
- Tags
- Share
- Author Brian Goetz
-
Quote
The possibility of incorrect results in the presence of unlucky timing is so important in concurrent programming that it has a name: a race condition. A race condition occurs when the correctness of a computation depends on the relative timing or interleaving of multiple threads by the runtime; in other words, when getting the right answer relies on lucky timing.
- Tags
- Share
- Author Brian Goetz
-
Quote
When a field is declared volatile, the compiler and runtime are put on notice that this variable is shared and that operations on it should not be reordered with other memory operations. Volatile variables are not cached in registers or in caches where they are hidden from other processors, so a read of a volatile variable always returns the most recent write by any thread.
- Tags
- Share
- Author Brian Goetz
-
Quote
Debugging tip: For server applications, be sure to always specify the -server JVM command line switch when invoking the JVM, even for development and testing. The server JVM performs more optimization than the client JVM, such as hoisting variables out of a loop that are not modified in the loop; code that might appear to work in the development environment (client JVM) can break in the deployment environment (server JVM).
- Tags
- Share
- Author Brian Goetz
-
Quote
From the perspective of a class C, an alien method is one whose behavior is not fully specified by C. This includes methods in other classes as well as overrideable methods (neither private nor final) in C itself. Passing an object to an alien method must also be considered publishing that object. Since you can’t know what code will actually be invoked, you don’t know that the alien method won’t publish the object or retain a reference to it that might later be used from another thread.
- Tags
- Share