BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 06-11-2009, 08:44 PM   #1 (permalink)
New Member
 
Join Date: Jun 2009
Model: 8310
PIN: N/A
Carrier: developer
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Why pushScreen in my thread will dead lock the simulator?

Please Login to Remove!

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;
		}
	}
}

Last edited by iwinyeah : 06-11-2009 at 08:45 PM.
Offline  
Old 06-11-2009, 09:49 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

What are you trying to do? I am confused that you have code after the call to enterEventDispatcher() but "under normal circumstances this method does not return".

The cause of the dead lock is probably due to waiting on eventVector in a block synchronized on eventVector and calling eventVector.notify() from an other block synchronized on eventVector. Only one thread at a time can be in a block synchronized to an object.
__________________
My other Blackberry is a PlayBook.
Offline  
Old 06-12-2009, 01:37 AM   #3 (permalink)
New Member
 
Join Date: Jun 2009
Model: 8310
PIN: N/A
Carrier: developer
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Talking Thanks!


I don't know ""under normal circumstances this method does not return"",and I move that line to the end of the method, it works!

Thanks!
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.