Java - Concurrency

Subscribe Send me a message home page tags


#java  #concurrency 

Building Blocks

Item handle() whenComplete() exceptionally()
Access to success? Yes Yes No
Access to failure? Yes Yes Yes
Can recover from failure? Yes No Yes
Can transform result from T to U? Yes No No
Trigger when success? Yes Yes No
Trigger when failure? Yes Yes Yes
Has an async version? Yes Yes Yes (Java 12)

Difference between Lock and Synchronized keyword

Difference between CountDownLatch and CyclicBarrier

CountDownLatch_and_CyclicBarrier.png

Fig 1: CountDownLatch and CyclicBarrier

Semaphore Analogy

semaphore.png

Fig 2: Semaphore

Java Memeory Model and Volatile keyword

Related Readings

Java Memory Model

In short, there are two types of issues in a multithreaded program:

and Java Meomery Model is used to define the behavior in a multithreaded environment.

Note:

1
2
3
4
5
6
7
private static class LazySomethingHolder {
  public static Something something = new Something();
}

public static Something getInstance() {
  return LazySomethingHolder.something;
}

Volatile Keyword

Thread

Life cycle of a thread

Notice that wait can only be called from a synchronized block.

There are two types of threads:

Note: Any thread inherits the daemon status of the thread that created it. The method setDaemon() can only be called after the thread object has been created and the thread hasn't been started.

ThreadPoolExecutor and ExecutorService

Parameters

ExecutorService

Note:

----- END -----

If you have questions about this post, you could find me on Discord.
Send me a message Subscribe to blog updates

Want some fun stuff?

/static/shopping_demo.png