Temporal woker shutdown

I am trying to do graceful shutdown of the workerFactory.

What i am trying to do is that, workerFactory.shutdown().
Once the shutdown method is called i am polling the workerFactory.isShutdown() and waiting until worker is shutdown.
Even if worker is not shutdown after 5 minute then i am calling shutDownNow() which i feel is not the right way of doing things.
Do we have another strategy besides waiting long for the worker factory to get shutdown ?

Use WorkerFactory.awaitTermination to wait.

This method will wait for given time interval.
If we provide wait time , then it will only wait for the given interval.
But if termination doesn’t happen within the given time interval then we will get stuck in waiting state.

You can call shutdownNow and wait again.

But shutdownNow will not be graceful one , it will terminate those works which are in pipeline.

What my concern is that what should be our strategy do shutdown and then restart the worker.
If we start shutdown which is not complete and in between we started the worker as well.

This method will wait for given time interval.
If we provide wait time , then it will only wait for the given interval.

You can specify a very large time interval to wait (10000 years?) if you want to wait forever.