8221892: ThreadPoolExecutor: Thread.isAlive() is not equivalent to not being startable

Reviewed-by: martin, dholmes
This commit is contained in:
Doug Lea 2019-05-02 06:33:28 -07:00
parent 9f5e9b5b5f
commit 82b990abc9
2 changed files with 47 additions and 2 deletions

View file

@ -922,13 +922,13 @@ public class ThreadPoolExecutor extends AbstractExecutorService {
if (isRunning(c) ||
(runStateLessThan(c, STOP) && firstTask == null)) {
if (t.isAlive()) // precheck that t is startable
if (t.getState() != Thread.State.NEW)
throw new IllegalThreadStateException();
workers.add(w);
workerAdded = true;
int s = workers.size();
if (s > largestPoolSize)
largestPoolSize = s;
workerAdded = true;
}
} finally {
mainLock.unlock();