[QFJ-475] ThreadPerSessionEventHandlingStrategy thread not exiting Created: 30/Sep/09  Updated: 15/Nov/12  Resolved: 05/Apr/10

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

Type: Bug Priority: Default
Reporter: jani Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Environment:

linux


Issue Links:
Duplicate
duplicates QFJ-410 ThreadPerSessionEventHandlingStrategy... Closed

 Description   

such thread do not exit on acceptor.stop()

stopDispatcherThreads iterates the collection after it clear()s it apparently so stopDispatcher() is not run on individual threads.

The the run method of ThreadPerSessionEventHandlingStrategy checks for the stopped variable and exits if set to true.
However it uses a blocking queue and if no messages come that variable is not checked so the thread can keep the app from exiting.

In stopDispatcherThreads() we can interupt the thread if the queue is empty. Alternately instead of messages.take() we can use messages.poll()
with a timeout, but than we need to check for null return.



 Comments   
Comment by jani [ 30/Sep/09 ]

I don't see how I can attach diffs so here it is what made it work for me

Index: core/src/main/java/quickfix/mina/ThreadPerSessionEventHandlingStrategy.java
===================================================================
— core/src/main/java/quickfix/mina/ThreadPerSessionEventHandlingStrategy.java (revision 926)
+++ core/src/main/java/quickfix/mina/ThreadPerSessionEventHandlingStrategy.java (working copy)
@@ -60,10 +60,10 @@

public void stopDispatcherThreads() {
Collection<MessageDispatchingThread> dispatchersToShutdown = dispatchers.values();

  • dispatchers.clear();
    for (MessageDispatchingThread dispatcher : dispatchersToShutdown) { dispatcher.stopDispatcher(); }

    + dispatchers.clear();
    }

class MessageDispatchingThread extends Thread

{ @@ -105,9 +105,11 @@ }

}
}

  • +
    public void stopDispatcher()

    { stopped = true; + if (messages.size() == 0) + interrupt(); }

    }

Generated at Sat Nov 23 14:36:27 UTC 2024 using JIRA 7.5.2#75007-sha1:9f5725bb824792b3230a5d8716f0c13e296a3cae.