Closed ssoundr closed 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.
Anyone get further on this?
Closing this.
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.