[QFJ-57] Make QFJ timer thread a daemon. Created: 25/Aug/06  Updated: 25/Jul/14  Resolved: 25/Jul/14

Status: Closed
Project: QuickFIX/J
Component/s: None
Affects Version/s: 1.0.2
Fix Version/s: 1.0.3

Type: Bug Priority: Default
Reporter: André Malenfant Assignee: Steve Bate
Resolution: Fixed Votes: 0
Labels: None


 Description   

There appears to be another "thread leak", at least in my environment. The faulty thread seam to be the QFC timer thread. I have created my own SocketInitiator to be able to override the time thread factory and so far I have discovered two things.

1- First, the method close on IOSessionInitiator never seems to be called.
2- The ScheduledExecutorService is never "shutdowned". Not sure if it has to be but if it's done, it fixes my problem.



 Comments   
Comment by Steve Bate [ 26/Aug/06 ]

The QFJ timer thread is shared by all sessions in all initiators and sessions. The ScheduledExecutorService can't be shutdown after an initiator or acceptor is stopped (unless I add some type of reference counting to it). Starting a new initiator or acceptor shouldn't create any more threads. Are you seeing multiple QFJ timer threads or just concerned that the thread still exists after you shut down your session connector?

Comment by Steve Bate [ 26/Aug/06 ]

The uncalled close method was a good catch. The ioSession is closed elsewhere so I'll remove that code, but I'm still investigating the reconnect job issues related to not calling close. Thanks.

Comment by André Malenfant [ 28/Aug/06 ]

I never see more than one QFJ Timer thread but it does not seem to be destroyed when I exit my application unless I manually terminate the VM. I was suspecting the QFJ Timer thread so I managed to override a few classes to gain control over it and shutting down the ScheduledExecutorService did the trick.

Maybe this only fixes my problem indirectly and the real issue lies somewhere else but I think it would be more elegant to gracefully shutdown the ScheduledExecutorService. I realize that the current implementation does not allow that but if there was one ScheduledExecutorService instance per initiator/acceptor instance it would be possible (in logoutAllSessions) and would not do any harm as I don't see much difference between 10 tasks on one thread and 5 tasks on 2 threads...

Comment by Steve Bate [ 28/Aug/06 ]

It sounds like your program's issue is caused by the QFJ thread not being a daemon thread. The QFTimerThreadFactory should set this flag so the thread doesn't keep the JVM from exiting. I'll make that change. Thanks for the report.

Comment by André Malenfant [ 28/Aug/06 ]

Funny because this was our first intuition and I did test the deamon thread fix but I must have done my testing wrong... Now it works.

I'll be waiting for an update, thanks for your responsiveness.

Comment by Steve Bate [ 02/Sep/06 ]

The fix for this problem for this problem has been added to the 1.0.x branch and the trunk.

Generated at Sat Nov 23 11:12:48 UTC 2024 using JIRA 7.5.2#75007-sha1:9f5725bb824792b3230a5d8716f0c13e296a3cae.