Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First of all, there is not such thing as stupid question...</p> <p><a href="http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Semaphore.html" rel="nofollow">Semaphore</a> allows multiple threads to "acquire" a resource. They should check if the resource is available. It's like a valve for flow control.</p> <p>A <a href="http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/Lock.html" rel="nofollow">Lock</a> is for exclusive access. Only one thread at a time. </p> <p>A <a href="http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html" rel="nofollow">ThreadPoolExecutor</a> allows you to run some code (Runnable or Callable class) using a bounded amount of threads. You don't have to bother about building this yourself, it is already implemented for you in the JSE API. You could do your own with some semaphores and queues... but if you do not have a good reason do not waste your time. </p> <p>Imaging you have to implement a web server that receives some request to port 80. You do not want to use the same thread that is listening this port to process the whole request (this is a waste of resources...). You could use a ThreadPoolExecutor deal with the request, process it and respond to the client. ThreadPoolExecutor could be configured to take advantage of the current CPUs: optimal number of threats for this architecture and this task.</p> <p><a href="http://www.javaconcurrencyinpractice.com/" rel="nofollow">Concurrency in practice</a> is a nice book to improve your knowledge on this matter. </p> <p>I hope this help you and sorry for my basic English.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload