Q:

shutdowning a fixed size thread pool

I use Executors.newFixedThreadPool to generate a thread pool, and want to shutdown it when the job queue is empty and no thread is working. How should I do that?

A:

You first need to shutdown your pool while letting all already submitted tasks to finish but not allowing new ones. Then you can block until the queue is empty and all tasks have completed:
pool.shutdown();
pool.awaitTermination(1, TimeUnit.HOUR);

ExecutorService.shutdown():

previously submitted tasks are executed, but no new tasks will be accepted

ExecutorService.awaitTermination():

Blocks until all tasks have completed execution after a shutdown request

