Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 3
Registered: ‎09-16-2008
My Device: Not Specified
Accepted Solution

run not being called in thread

I'm trying to get a thread running in the background to update a label field in a MainScreen but for some reason the thread's run() method is not being called. I'm using JDE 4.3.0.

 

package UpdateTest; import net.rim.device.api.ui.UiApplication; import net.rim.device.api.ui.component.LabelField; import net.rim.device.api.ui.container.MainScreen; import net.rim.device.api.ui.component.Dialog; import net.rim.device.api.system.DeviceInfo; import java.lang.Runnable; import java.lang.Thread; public class UpdateTest extends UiApplication { public UpdateTest() { pushScreen(new UpdateTestScreen()); } public static void main(String[] args) { UpdateTest bm = new UpdateTest(); bm.enterEventDispatcher(); } } final class UpdateTestScreen extends MainScreen { LabelField _field; UpdateThread upThread; public UpdateTestScreen() { super(); upThread = new UpdateThread(); upThread.start(); setTitle("Update field test"); add( new LabelField("field: ") ); _field = new LabelField("0"); add(_field); } public boolean onClose() { Dialog.alert("exit"); upThread.stop(); System.exit(0); return true; } public class UpdateThread extends Thread { private volatile boolean _start = false; private volatile boolean _stop = false; private static final int TIMEOUT = 500; public UpdateThread() { super(); System.out.println("UpdateThread Created"); } public void stop() { _stop = true; System.out.println("UpdateThread Stopped"); } public void start() { _start = true; System.out.println("UpdateThread Started"); } public void run() { System.out.println("UpdateThread running"); for(;;) { while( !_start && !_stop) { try { sleep(TIMEOUT); System.out.println("UpdateThread sleeping"); } catch (InterruptedException e) { System.err.println(e.toString()); } } if (_stop) return; UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { _field.setText("" + System.currentTimeMillis()); } }); System.out.println("invoked"); } } } }

 

Please use plain text.
Developer
richard_puckett
Posts: 191
Registered: ‎04-03-2008
My Device: Bold 9700

Re: run not being called in thread

If you're going to override Thread.start then call super.start() in there somewhere, like after your sysout.

Please use plain text.
New Developer
Posts: 3
Registered: ‎09-16-2008
My Device: Not Specified

Re: run not being called in thread

Silly me. I didn't realize I was overriding a Thread method. Thanks!
Please use plain text.