Originally posted by ulvi ugur:
Hi Paul,
Thanks for your reply. It might be an interesting idea to use join() but I can't figure out how. As far as I understand, join() has a connection with run(), meaning main thread can be blocked with t.join() until the job in run() is completed.
IMHO could more apply for a "Worker" scenario. But a connection is not a synchronous event, and whatever I do in run() of this additional thread, connection event will always be thrown in processEvent(Event e) method.
Can't figure out how I can sort this out with join(), any example you can post ? Or did you mean something different ?
Thanks in advance,
Ulvi
Steve
From the sounds of it, it looks like the API was designed for you to create the connection and be done. Then use the processEvent(Event e) method of whatever listener to continue doing work. You may find it easier to move the code into that event method rather than where you have it. You should read up on what thread the processEvent(Event e) method gets executed in, though. If your work is time consuming you don't want to block GUI/streaming functionality, and so might want to start a new thread to do the work.
Originally posted by ulvi ugur:
Hi Steve,
Thanks for your comments.
--> I could do this theoritically but it would not be a clear design to me as the main thread would initiate the connection and not have a clear function call series. I would prefer a sequence in the main thread like :
connect();
subscribe();
collectdata();
processdata();
Your second idea might be a good idea although I think it is a sidekick. To be honest, I probably expected to find a better solution, somehow.
Steve
Steve
Originally posted by Anton Golovin:
Ulvi, join() is the way you wait on a thread in Java. Interesting or not, this is the only way.
Steve
Originally posted by Steve Luke:
Hi Anton, the problem with join is that the other thread has to finish before the join completes. In Ulvi's situation the other thread has to continue processing, and the main thread just needs to be aware of when certain events take place. So join isn't the appropriate tool, either event dispatching or synchronized notices is.
Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|