1) Semaphore Basically, a counter that limits the number of concurrent threads accessing a specific resource. In general, to use a semaphore, the thread that wants access to the shared resource tries to acquire a permit. If the semaphore’s count is greater than zero, then the thread acquires a permit, which causes the semaphore’s count to be decremented. Otherwise, the thread will be blocked until a permit can be acquired. When the thread no longer needs an access to the shared resource, it releases the permit, which causes the semaphore’s count to be incremented. If there is another thread waiting for a permit, then that thread will acquire a permit at that time. Java provide Semaphore class in java.util.concurrent package that implements this mechanism, so you don’t have to implement your own semaphores. 1.1) Constructor Semaphore(int permits): creates Semaphore with given number of permits and nonfair fairness setting. Semaphore(int permits, boolean fair...
Comments
Post a Comment