From the Java java.util.concurrent.Semaphore docs, I was not quite clear what would happen if the .acquire () semaphore blocks the thread and then an InterruptedException is thrown. Is the value of the semaphore reduced, and is there a need to free the semaphore?
I am currently using the following code:
try { // use semaphore to limit number of parallel threads semaphore.acquire(); doMyWork(); } finally { semaphore.release(); }
Or is it better for me not to call release () when an InterruptException occurs during fetch ()?
java semaphore
kasimir
source share