Вопрос

My app starts a daemon thread which uses a blockingQueue. When it is killed using kill -3, the app doesnt stop cleanly and the resulting stack shows that it is still waiting on BlockingQueue.take().

Any suggestions to help with a clean shutdown would be deeply appreciated

Это было полезно?

Решение

You say...

...When it is killed using kill -3, the app doesnt stop cleanly and the...

Usually a Java app does not terminate by using Kill -3.

Kill SIGQUIT (-3) is used to take a Java thread dump.

Try using kill -9 or -15

If some special signal handling hook is enabled, this behaviour could change.

EDIT:

Also, a controlled, clean Java app shutdown is originated within the app.
Have a look at How to gracefully handle the SIGKILL signal in Java

Другие советы

BlockingQueue#take respond to interruption, so you simply need to make sure that you interrupt the thread that executes the take method and handle the thrown InterruptedException adequately (i.e. by exiting the method).

If the thread in question is managed by a thread pool, you can shutdownNow the pool, which will interrupt the thread too.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top