Java Concurrency in Practice
Rate it:
Open Preview
7%
Flag icon
must do so in a thread-safe manner.
7%
Flag icon
encapsulation, immutability, and clear specification of invariants—
8%
Flag icon
makes sense only if the class encapsulates its own state.
8%
Flag icon
Correctness means that a class conforms to its specification.
8%
Flag icon
Stateless objects are always thread-safe.
8%
Flag icon
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.
9%
Flag icon
while you are in mid-update.
9%
Flag icon
The definition of thread safety requires that invariants be preserved regardless of timing or interleaving of operations in multiple threads.
9%
Flag icon
Reentrancy means that locks are acquired on a per-thread rather than per-invocation basis. [7]
10%
Flag icon
Every shared, mutable variable should be guarded by exactly one lock. Make it clear to maintainers which lock that is.
11%
Flag icon
Avoid holding locks during lengthy computations or operations at risk of not completing quickly such as network or console I/O.
11%
Flag icon
always use the proper synchronization whenever data is shared across threads.
12%
Flag icon
Locking can guarantee both visibility and atomicity; volatile variables can only guarantee visibility.
12%
Flag icon
Do not allow the this reference to escape during construction.
13%
Flag icon
It is safe to perform read-modify-write operations on shared volatile variables as long as you ensure that the volatile variable is only written from a single thread.
14%
Flag icon
Immutable objects can be used safely by any thread without additional synchronization, even when synchronization is not used to publish them.
14%
Flag icon
because of internal synchronization in the JVM, this mechanism is guaranteed to safely publish any objects initialized in this way
15%
Flag icon
but also every time the object is accessed to ensure visibility of subsequent modifications.
15%
Flag icon
The built-in mechanisms for efficiently waiting for a condition to become true—wait and notify—are tightly bound to intrinsic locking, and can be difficult to use correctly.
16%
Flag icon
Encapsulating data within an object confines access to the data to the object's methods, making it easier to ensure that the data is always accessed with the appropriate lock held.
16%
Flag icon
would do just as well.
16%
Flag icon
The primary advantage of the Java monitor pattern is its simplicity.
17%
Flag icon
attempt to respect this invariant, but do so poorly.
17%
Flag icon
composite
17%
Flag icon
a variable is suitable for being declared volatile only if it does not participate in invariants involving other state variables.
18%
Flag icon
Document a class's thread safety guarantees for its clients; document its synchronization policy for its maintainers.
19%
Flag icon
by the same “it would be absurd if it weren't” argument, we have no choice but to assume that DataSource.getConnection does not require additional client-side locking.
19%
Flag icon
impairing
20%
Flag icon
hurts application scalability.
20%
Flag icon
in the degenerate case,
20%
Flag icon
The iterators returned by ConcurrentHashMap are weakly consistent instead of fail-fast.
20%
Flag icon
these quantities are moving targets.
20%
Flag icon
On the whole, though,
20%
Flag icon
results only in better scalability.
21%
Flag icon
a put on an unbounded queue never blocks.
21%
Flag icon
A thread-confined object is owned exclusively by a single thread, but that ownership can be “transferred” by publishing it safely where only one other thread will gain access to it and ensuring that the publishing thread does not access it after the handoff.
21%
Flag icon
Work stealing is well suited to problems in which consumers are also producers—
22%
Flag icon
result-bearing
23%
Flag icon
The key difference is that with a barrier, all the threads must come together at a barrier point at the same time in order to proceed.
23%
Flag icon
Latches are for waiting for events; barriers are for waiting for other threads.
24%
Flag icon
All concurrency issues boil down to coordinating access to mutable state.
24%
Flag icon
Make fields final unless they need to be mutable.
24%
Flag icon
Immutable objects are automatically thread-safe.
24%
Flag icon
Encapsulation makes it practical to manage the complexity.
24%
Flag icon
Guard each mutable variable with a lock.
24%
Flag icon
Guard all variables in an invariant with the same lock.
24%
Flag icon
Hold locks for the duration of comp...
This highlight has been truncated due to consecutive passage length restrictions.
24%
Flag icon
A program that accesses a mutable variable from multiple threads without synchroniza...
This highlight has been truncated due to consecutive passage length restrictions.
24%
Flag icon
Don't rely on clever reasoning about why you don't ne...
This highlight has been truncated due to consecutive passage length restrictions.
24%
Flag icon
Include thread safety in the design process—or explicitly document that your c...
This highlight has been truncated due to consecutive passage length restrictions.
« Prev 1 3