Thursday, March 20, 2008

Java Thread Programming : Using Semaphores

The java concurrent framework provides Semaphore . Semaphores are useful when the end user wants to implement some kind of resource pool.

In a semaphore permits can be acquired and released . A semaphore when created can be initialized with the number of entries it can contain at any point of time .

Semaphore s = new Semaphore(N);

// acquire a permit

s.acquire();

// release a permit

s.release();

No comments: