synchronized block vs ReentantLock performance
Java synchronized block vs ReentantLock performance
Result summary
Result (100000 run, 10 thread)
Time [ms] | |
Without synchronization | 282 |
Synchronized block | 7453 |
ReentrantLock lock | 516 |
ReentantReadWriteLock read lock | 344 |
ReentantReadWriteLock write lock | 516 |
Conclusion: The java new locking mechanism is significant faster than old synchronized block strategy, in the result you can see the read/write lock benefits, because it's not block the other threads.
ps: In the test, we only get one item from HashMap, and after that we call Thread.yield (emulate the running thread changed before unlock the resource).
page revision: 1, last edited: 05 Oct 2009 15:34