SumZeroTrading
SumZeroTrading copied to clipboard
IB Disconnection
I have noticed that there are some threads running after calling the InteractiveBrokersClientInterface.unsubscribeLevel1() method as well as InteractiveBrokersClientInterface.disconnect(). Are there any methods which can be used to close the running threads after the connect() method and subscribeLevel1() method?
There is a thread running to process the internal queue of IB data from the level 1&2 subscribers, and order events. Is there an issue with these threads continuing to run even if there are no current level 1 subscribers?
The program need to have proper exit. In order to exit properly, we need to stop the running threads. Is there anyway to stop it?
I see. Probably the easiest thing to do will be to convert the threads to daemon threads, so if they are still running when the main thread stops, the application will shut down without needing to stop the daemon threads.
Hi Rob,
I think what Vince mentioned was partly caused by blocked threads in IBQuoteProcessor.
public void run() {
while( shouldRun ) {
try {
processData( quoteBlockingQueue.take() );
} catch( Exception ex ) {
//logger.error(ex, ex);
ex.printStackTrace();
}
}
}
When stopProcessor() method was called, shouldRun is changed to false with intention to exit the while loop, but the thread could be permablocked if no new data is put into the queue. I suggest to also interrupt this thread in stopProcessor()
Ok, I see what you are saying now. You're right, if you aren't subscribed to any quotes, or if its after market hours and no quotes are coming in. The other option would be to use the poll(long timeout, TimeUnit unit) on the blockingQueue rather than take(), and give it a 500ms or so timeout value, so if there was nothing in the queue, the operation would timeout, it would see shouldRun is false, and exit the loop.