문제

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