forcedotcom / EMP-Connector

A simplified cometd connector for Enterprise Messaging Platform
BSD 3-Clause "New" or "Revised" License
185 stars 243 forks source link

EmpConnector Keep alive scheduler is not stopped upon Connector stop. #12

Closed ssoundr closed 6 years ago

ssoundr commented 7 years ago

Problem:

When the EmpConnector is initialized using the below constructor

public EmpConnector(BayeuxParameters parameters) { this(parameters, Executors.newSingleThreadScheduledExecutor()); }

New singleThreadScheduledExecutor thread is automatically created. This scheduler thread is never getting shutdown when the connector was stopped. Also, the application is not having the access to private member scheduler to do a shutdown.

Any application usage of creating EmpConnector on the fly is leading to thread leak.

Workaround: The only way to avoid this issue is by calling the other constructor with application taking care of the scheduler lifecycle. public EmpConnector(BayeuxParameters parameters, ScheduledExecutorService scheduler)

Solution: Instead of creating a scheduler every time the EmpConnector is created, use a singleton scheduler to reuse the scheduler.

Thanks Suriya.

Nivedita1201 commented 6 years ago

Hi Suriya,

Thanks for sharing the information. It is very useful. I am currently using EmpConnector(BayeuxParameters parameters) constructor in my EmpConnector java code listner and facing memory issues; hence would like to switch to EmpConnector(BayeuxParameters parameters, ScheduledExecutorService scheduler) constructor .

could you please assist me with the link/document where I can get more in-site on EmpConnector constructor ? As the EmpConnector.jar file I have is not showing up the EmpConnector(BayeuxParameters parameters, ScheduledExecutorService scheduler) constructor.

Thanks in advance.

troysellers commented 6 years ago

Anyone get further on this?

pbn-sfdc commented 6 years ago

Closing this.