Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SwingWorker - How not to block EDT

843807Jul 15 2010 — edited Jul 16 2010
In our Swing app, we are using SwingWorker for each Server side calls that makes a Database request and returns the rowset.

What I am noticing is even though the UI is not greyed out while its making a server call, its not letting me use other parts of the app like clicking on the menu etc.

This is how the calls looks. I am calling get() after the start() method, but only after checking is the worker is done().

This should not block the EDT thread right? Please let me know if its alright.

public Object doAsynServletCommunication(RequestMap requestMap, URL servletUrl, String sMessage, Frame frame, boolean bCancelEnabled) throws Exception {

TestSwingWorker worker = new TestSwingWorker (this, requestMap, servletUrl);
worker.start();

if(worker.isDone()) {
try {
return worker.get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// If not an event Thread, so synchronized communication
return doServletCommunication(requestMap, servletUrl);
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 13 2010
Added on Jul 15 2010
5 comments
265 views