Показаны сообщения с ярлыком ThreadLocal. Показать все сообщения
Показаны сообщения с ярлыком ThreadLocal. Показать все сообщения

понедельник, 8 февраля 2010 г.

ThreadLocal: history of performance improvment

From "Threading lightly, Part 3: Sometimes it's best not to share. Exploiting ThreadLocal to enhance scalability"

ThreadLocal performance
While the concept of a thread-local variable has been around for a long time and is supported by many threading frameworks including the Posix pthreads specification, thread-local support was omitted from the initial Java Threads design and only added in version 1.2 of the Java platform. In many ways, ThreadLocal is still a work in progress; it was rewritten for version 1.3 and again for version 1.4, both times to address performance problems.

In JDK 1.2, ThreadLocal was implemented in a manner very similar to Listing 2, except that a synchronized WeakHashMap was used to store the values instead of a HashMap. (Using WeakHashMap solves the problem of Thread objects not getting garbage collected, at some additional performance cost.) Needless to say, the performance of ThreadLocal was quite poor.

воскресенье, 4 октября 2009 г.

Concurrency lessons from eBay engineers

On JavaOne Technical Sessions 2009 3 engineers from eBay speek about Java concurrency troubles/lessons that they learned.
- Lazy Initialization patern
- Holder pattern
- correct Double-Checked Locking pattern
- Interesting example: ConcurrentMap of AtomicInteger
- DateFormat, MessageDigest, CharsetEncoder/CharsetDecoder - not thread safe
- ThreadLocal pattern
- potential lock contention on Class.forName(...) when missing class
- SAXParserFactory.newInstance().newSAXParser() - potentially significant lock contention on META-INF
P.S. You MUST be resistered at Sun. Its easy.
P.P.S. And, Yes, eBay, Amazon and part of Google writed in Java:)