Cases of Using Java Parallel Utilities

I read Java Concurrency in Practice and this is a great reference, but I would like to get a brief overview of individual examples of using the java.util.concurrent package.

For example:

  • Why use a parallel collection for a synchronized collection?
  • When should atomic classes be preferred over explicit blocking?
  • When should you use synchronization locks?
  • What are the alternatives to wait () and notify (), notifyAll ()?
  • When should I use CompletionService?

What are the pros and cons to know?

+5
source share
2 answers
  • Why use a parallel collection for a synchronized collection?

synchronized - . , synchronized . - a ConcurrentMap.putIfAbsent - compareAndSet, Map .

  • ?

AtomicInteger AtomicLong ( ) , . :

synchronized (lock) { 
    int old = counter;
    counter++;
    return old;
}

:

int old = counter.getAndIncrement();

, , . , , wait boolean. WaitableBoolean Doug Lea concurrency, j.u.c, , .

  • ?

, Locks . , , ReadWriteLock . , , , . synchronized .

  • wait() notify(), notifyAll()?

await, signal signalAll

  • CompletionService?

, , , , , ( ) . , , ( ), .

+11
What are the alternatives to wait() and notify(), notifyAll()

wait(), notify() notifyAll() .

200KLOC codebase , . / ..

wait(), notify() notifyAll() ?

.

, : * , , java.util.concurrent. ** whatnot . wait(), notify() notifyAll(): .

, / concurrency.

, " Java", "":

" , , ".

+2

All Articles