Semaphores and threads in Java

I do not really understand the concept of semaphores in Java and try to understand it.

My understanding after reading the oracle docs (http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/Semaphore.html) and some other pages that looks like a lock with counting the number of permissions.

It is usually used to create resource pools. I got confused here, there is also a ThreadPoolExecutor that can give me a thread pool. So what is the difference? Which one is used in which scenario?

+5
source share
2 answers

First of all, there is no such thing as a stupid question ...

Semaphore "" . , . .

A Lock . .

A ThreadPoolExecutor ( Runnable Callable) . , , JSE API. ... , .

-, 80. , ( ...). ThreadPoolExecutor , . ThreadPoolExecutor : .

Concurrency - , .

, .

+4

A ThreadPool - , . Java ThreadPoolExecutor , Runnable Callable , , .

, . . , , .

BTW: Java 7, Java 5.0 EOL , Java 6 .

+1

All Articles