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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


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

 

Developer
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.

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!