开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

Connect to TWS in main not in Thread (Java)


twsapi
 

Hi board,

I have a question regarding the thread programming in Java with the IB API. In the example application (Example 1) you see that first the main class is called and within that class a new thread is called e.g. new Example1(args[0]).start();
If I move the connect call to TWS e.g. connectToTWS(); into the main class the thread will not see/be able to access the open connection to TWS.

My question is now, why is the thread not able to use the opened connection within main but need its own connection call? And can I actually use just one connection call in main to be used by multiple threads?

What I want to achieve is that the main class opens the initial call to TWS and holds this open while different threads can use this open connection. As every call of connectToTWS(); requires me to allow access in the TWS client I only want to authorize my program once not every time a thread actually opens the connection. Not much of automation when I need to authorize it manually every time :)

Thanks so much for your help!

Regards

Join [email protected] to automatically receive all group messages.