You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/09/06 10:42:05 UTC

[GitHub] [pulsar] lhotari commented on issue #17480: [Bug][Java client] main thread won't exit if not close pulsar client

lhotari commented on issue #17480:
URL: https://github.com/apache/pulsar/issues/17480#issuecomment-1237979028

   > We (+ @yaalsn) discuss this, seems that netty has a shutdown hook to prevent client exit.
   
   Live non-daemon threads are a common reason why normal shutdown doesn't happen in a Java application.
   
   The [javadoc of java.lang.Thread](https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html):
   
   >  When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls the method named main of some designated class). The Java Virtual Machine continues to execute threads until either of the following occurs:
   > 
   > * The exit method of class Runtime has been called and the security manager has permitted the exit operation to take place.
   > * All threads that are not daemon threads have died, either by returning from the call to the run method or by throwing an exception that propagates beyond the run method.
   
   I believe that Pulsar client creates threads that are non-daemon threads. This might be intentional. 
   I assume that it's better to handle the shutdown in a controlled way in any case. 
   A simple fix to your problem is to add a shutdown hook that calls `client.close()`. 
   
   @labuladong What is your actual use case? Could you share more of the scenario that you have in mind?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org