The code under will deadlock the simulator, What is wrong?
Code:
public class AccountApplication extends UiApplication implements Runnable, EventListener {
public static AccountApplication app;
private Vector eventVector;
public static void main(String[] args) {
app = new AccountApplication();
app.enterEventDispatcher();
Event ev = (Event)BaseRecord.getInstance(Event.class);
ev.type = Event.SYS_LOAD;
app.notifyEvent(ev);
}
public AccountApplication() {
eventVector = new Vector(4);
new Thread(this).start();
// // The code place here is ok
// StartupScreen startup = new StartupScreen();
// startup.setStatus(StartupScreen.SHOW_LOGO);
// pushScreen(startup);
}
public void notifyEvent(Event ev) {
synchronized (eventVector) {
eventVector.addElement(ev);
eventVector.notify();
}
}
public void run() {
Event nowEvent = null;
while (true) {
synchronized (eventVector) {
while (eventVector.size() <= 0) {
try {
eventVector.wait();
} catch (InterruptedException e) {
//
}
}
nowEvent = (Event) eventVector.firstElement();
eventVector.removeElement(nowEvent);
}
switch (nowEvent.type) {
case Event.SYS_LOAD:
app.invokeLater(new Runnable(){public void run(){
StartupScreen startup = new StartupScreen();
startup.setStatus(StartupScreen.SHOW_LOGO);
pushScreen(startup);
}});
break;
case Event.SYS_EXIT:
System.exit(0);
}
BaseRecord.backInstance(nowEvent);
nowEvent = null;
}
}
}