The thread pool executor takes a blocking queue as its argument (i.e. the work queue) which according to the API’s is used for “… holding tasks before they are executed”
If a thread pool executor is permitted a maximum of 2 threads and has a fixed size work queue of 1 ….. if the main thread calls submit() twice before one of the pooled threads has a chance to execute will this result in the second call to submit() throwing an exception because of the size of the work queue being exceeded.
I’m just slightly confused by the following description from the API:
• If fewer than corePoolSize threads are running, the Executor always prefers adding a new thread rather than queuing.
• If corePoolSize or more threads are running, the Executor always prefers queuing a request rather than adding a new thread.
• If a request cannot be queued, a new thread is created unless this would exceed maximumPoolSize, in which case, the task will be rejected.
As “fewer than corePoolSize threads are running”, i.e. no threads are running, does the work queue actually get used (and so is its size relevant)?