Synchronized Vs Semaphore

前端 未结 3 681
[愿得一人]
[愿得一人] 2021-02-07 01:18

While reading concurrency in Java, I have following doubts:

  1. Does Java provides lower level construct then synchronized for synchronization?

  2. In

3条回答
  •  感情败类
    2021-02-07 01:18

    1. There is also volatile keyword, according to http://docs.oracle.com/javase/tutorial/essential/concurrency/atomic.html volatile variable access is more efficient than accessing these variables through synchronized code

    2. java.util.concurrent.Semaphore is used to restrict the number of threads that can access a resource. That is, while synchronized allows only one thread to aquire lock and execute the synchonized block / method, Semaphore gives permission up to n threads to go and blocks the others.

提交回复
热议问题