Day 2: Beyond Intrinsic Locks
Day 1 covered Javaâs Thread class and the intrinsic locks built into every Java object. For a long time this was pretty much all the support that Java provided for concurrent programming. Java 5 changed all that with the introduction of java.util.concurrent. Today weâll look at the enhanced locking mechanisms it provides.
Intrinsic locks are convenient but limited.
-
There is no way to interrupt a thread thatâs blocked as a result of trying to acquire an intrinsic lock.
-
There is no way to time out while trying to acquire an intrinsic lock.
-
Thereâs exactly one way to acquire an intrinsic lock: a synchronized block.
â âsynchronizedâ(object) {â use shared resourcesâ }This means that lock ...
Get Seven Concurrency Models in Seven Weeks now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.