AQS component summary.

  • Semaphore – Allows simultaneous access by multiple threads: Synchronized and ReentrantLock allow only one thread to access a resource at a time, and Semaphore allows multiple threads to access a resource at the same time.
  • CountDownLatch (backtimer) : CountDownLatch is a synchronization utility class that coordinates synchronization between multiple threads. This tool is usually used to control thread waiting, which allows a thread to wait until the countdown is over before starting execution.
  • CyclicBarrier: A CyclicBarrier is very similar to CountDownLatch in that it can also implement technical waits between threads, but it is more complex and powerful than CountDownLatch. The main application scenario is similar to CountDownLatch. CyclicBarrier literally means a Barrier that is Cyclic. What it does is let a group of threads block when they reach a screen barrier (also known as a synchronization point), and the barrier will not open until the last thread reaches the barrier, and all threads blocked by the barrier will continue to work. The CyclicBarrier’s default constructor is CyclicBarrier(int parties), whose argument is the number of threads that the barrier intercepts, and each thread calls the await method to tell the CyclicBarrier that I have reached the barrier and the current thread is blocked.