You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Matthew Broadhead <ma...@nbmlaw.co.uk.INVALID> on 2021/05/28 09:35:06 UTC

ejb singleton not closing thread

i am trying to subscribe to a nats streaming server in a singleton. the 
idea is that it will listen for any messages from the queue while the 
server is running.

it looks like it might work ok in production but during development if i 
make any code change then it blows up with 
org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads 
The web application [api] appears to have started a thread named 
[jnats-streaming ack timeout thread] but has failed to stop it. This is 
very likely to create a memory leak.

i have created a gist 
https://gist.github.com/chongma/2a3ab451f2aeabc98340a9b897394cfe

is there any way to make sure the thread gets shut down when the web 
application is stopped?



Re: ejb singleton not closing thread

Posted by Matthew Broadhead <ma...@nbmlaw.co.uk.INVALID>.
following this stackoverflow post seems to have fixed it:
https://stackoverflow.com/questions/39080296/hazelcast-threads-prevent-tomee-from-stopping 


creating a default producer:
@ApplicationScoped
public class NatsConnectionProducer {

     @Resource(name = "baseAddressNats")
     private String baseAddressNats;

     @Produces
     @ApplicationScoped
     public StreamingConnection instance() throws IOException, 
InterruptedException {
         StreamingConnectionFactory cf = new 
StreamingConnectionFactory(new Options.Builder().natsUrl(baseAddressNats)
.clusterId("cluster-id").clientId("client-id").build());
         return cf.createConnection();
     }

     public void destroy(@Disposes final StreamingConnection instance)
             throws IOException, TimeoutException, InterruptedException {
         instance.close();
     }
}

On 28/05/2021 11:35, Matthew Broadhead wrote:
> i am trying to subscribe to a nats streaming server in a singleton. 
> the idea is that it will listen for any messages from the queue while 
> the server is running.
>
> it looks like it might work ok in production but during development if 
> i make any code change then it blows up with 
> org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads 
> The web application [api] appears to have started a thread named 
> [jnats-streaming ack timeout thread] but has failed to stop it. This 
> is very likely to create a memory leak.
>
> i have created a gist 
> https://gist.github.com/chongma/2a3ab451f2aeabc98340a9b897394cfe
>
> is there any way to make sure the thread gets shut down when the web 
> application is stopped?
>
>