Reputation: 330
I came across the following piece of code in my code base and I dont understand how it works.I'm a bit of a novice at Swing, hence sorry if it seems like a silly question.
public static void invokeOnEventDispatchThread(Runnable r){
try{
if(SwingUtilities.isEventDispatchThread()){
r.run();
}else{
SwingUtilities.invokeAndWait(r);
}
}catch(Exception e){
;
}
}
Here will r.run() be invoked immediately in the event dispatch thread? Is the point of the method that r.run() be called asap, moving it to the head of the queue?
Thanks.
Upvotes: 1
Views: 23
Reputation: 328598
The point of the method is to run the code synchronously:
In particular, the javadoc for invokeAndWait states that the method should not be called on the EDT hence the 2 branches in your code.
Upvotes: 1