Here is my code:
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
try {
Event e1 = new Event();
e1.type = EVT_CONNECTING;
for (Listener listener : listeners) {
listener.handleEvent(e1);
}
database = new Database(cp.getName(), cp.getConnection());
Event e2 = new Event();
e2.type = EVT_CONNECT_SUCCESS;
for (Listener listener : listeners) {
listener.handleEvent(e2);
}
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
Event e = new Event();
e.text = ex.getMessage();
e.type = EVT_CONNECT_FAILD;
for (Listener listener : listeners) {
listener.handleEvent(e);
}
}
}
});
In above code, I try to connect to a database. Sometimes this will take a long while to give response (network connection timeout for example), but when the Runnable
begin to run, the user interface lose response. Why?