Why was SwingUtilitie.invokeLater() and invokeAndWait() method is designed in such a way that they accept RUNNABLE instances.
They could have created some new interfaces for this...
Why would you need a new interface when an existing one is just fine? What would you need besides executing some code? Would you need parameters, and if so which ones?
I dont need to create any new interfaces.
Just wanted to understand why do these two methods take in Runnables.
Not sure if this is right or not. Is it because internally all events in EventQueue are separate tasks and It will be easy for EventQueue to pick up each and every runnable and call run() on them?
Exactly. Sun could have decided to create a new interface, but they saw that Runnable was already there and provided them with all they needed - a single "run" method. The only possible problem with Runnable.run() is that it cannot throw any checked exceptions. Sun fixed that in java.util.concurrent.Callable, which also returns a value, but for Swing applications neither is really necessary.
Karthick Dharani Vidhya
Ranch Hand
Joined: Feb 23, 2008
Posts: 88
posted
0
I just came to know about Callable after your reply.