|
|
||
Tom White's BlogJ2SE ArchivesAre your beans thread-safe?Posted by tomwhite on September 21, 2006 at 01:55 PM | Permalink | Comments (27)[Update: changed wording per comments to fix error.] Dependency injection is pretty well established these days, with plenty of Inversion of Control containers available to manage your beans. I'm currently reading Java Concurrency in Practice by Brian Goetz et al, which got me thinking about the thread-safety of large object graphs managed by IoC containers.
In most applications I've seen, the common usage pattern is to use dependency injection to wire up your object graph in one go when the application starts. After that the application uses the object graph, and effectively treats it as being immutable. For example, in an application for buying books we might have a
The problem is that it's not clear that this code is thread-safe. Unless the container publishes the
Thankfully, this is easy to fix. We can mark the
Alternatively, we can use constructor injection and
The Future
So could the IoC container providers take steps to ensure that application developers don't have to worry about thread safety in wiring up object graphs? Possibly, although at the time of writing it is less than clear whether the popular containers do or not. Tim Peierls, one of the authors of Java Concurrency in Practice, wrote in a email to me that "Until it's proven safe, I have adopted a rule that all such setter-injected effectively immutable fields must be volatile." He also suggested marking the field with an annotation, such as Counting CharactersPosted by tomwhite on March 22, 2005 at 02:10 PM | Permalink | Comments (4)
During a panel discussion at the 1999 JavaOne conference Bill Joy, talking about the things he didn't like about Java, stated that he "didn't want
It was Unicode 3.1 that introduced supplementary characters: characters that require more than 16 bits to represent them. (These characters are rare - think obscure mathematical symbols and languages no longer used outside academia - like Linear B.) Since Java tracks the Unicode standard, the next release - 1.5 - had to solve the problem of how to represent these characters given that a Java
For reasons of backward compatibility the fix broke the one-to-one correspondence between Unicode characters and Java The Java Language Specification, 3rd EditionPosted by tomwhite on February 28, 2005 at 02:16 PM | Permalink | Comments (6)There was no fanfare, in fact it's not even linked to from the JDK 1.5 documentation, but the third edition of the Java Language Specification is available for "maintenance review". I only found it because I wondered if a new version of the JLS had been produced for 1.5, and went out looking for it. The changes are only "proposed" changes - it is odd that they didn't go final with the release of 1.5.0 - and there's even a language change from 1.4 in there too (assertions). Presumably it will be finalised when the book is printed. There have been some big changes in Java recently so it's good that the JLS has had a bit of work done on it as it was looking a bit forgotten. Here's a list of the new language features by chapter:
It's probably worth a re-read. | ||
|
|