Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SwingUtilities.invokeLater and invokeAndWait....

 
Karthick Dharani Vidhya
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Recently I came across a interesting question.

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...

Any info on this would be really helpful.
 
Rob Spoor
Sheriff
Pie
Posts: 20533
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Karthick Dharani Vidhya
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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?
 
Rob Spoor
Sheriff
Pie
Posts: 20533
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just came to know about Callable after your reply.

Thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic