09-29-2011 06:35 AM
When creating a new thread in order to not hold up the event dispatcher it is required to spawn threads (I could be corrected on this statement).
Is there a difference beween using invokeLater and using the pure "java" way of creating a new thread, i.e implementing Runnable interface.
10-07-2011 12:39 PM
How are you doing? I hope all is well.
I hope you have found the answers to your question, but if not:
The main difference between invokeLater(new Runnable) and new Runnable is that invokeLater puts an action into the event queue. So that whenever the main event tasks are completed, the new Runnable will get processed.
A new Runnable() is an interface that will be executed whenever its called regardless if its on the main event thread. You can create a new thread to put a runnable in so that a new thread can be spawned.
Thread th = new Thread(myRunnable);
spawns off a new thread.
Let me know if you have any further questions or doubts, and I will be glad to answer them for you.
10-07-2011 09:35 PM
Just adding a little to the previous answer, which I hope helps.
invokeLater does not create a new Thread, it just schedules a Runnable to be executed on the Event Thread. This is the correct approach if you want to update the UI, since that needs to run on the Event Thread (or to be completely accurate, needs to run with the Event Lock).
However if you have some long running background processing, or some blocking operation (like network interaction), then you really want to run this in your own Thread,- if you try to use the Event Thread, you will be blocking the User interactions.
So the two are not different ways to do the same thing. You will choose one way or the other depending on what you are trying to achieve.
Review this for more informaiton:
Do a search for Event Thread - there are other interesting KB articles too.