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
Developer
Posts: 70
Registered: ‎08-18-2008
My Device: Not Specified

Thread.sleep(1000) - sometimes hangs emulator!!

Hi,

 

I'm using JDE 4.3.0 r1 to develop a j2me app for blackberry.

 

My app has its main thread, and a persistent background thread which simply loops and sleeps, like:

 

    public void run() 

    {

        while (m_run) {

            for (int i = 0; i < 30; i++) {

                if (!m_run) { 

                    break;

                }

                

                try { Thread.sleep(1000); } catch (Exception ex) {}  // problem here!

            }

        }

    }

 

This works fine most of the time, however when I leave the app running in the emulator for more than a few minutes, it *sometimes* seems that the whole emulator stops behaving normally. When I get to the Thread.sleep() statement, I never exit it. I can press a key on the emulator and this some how wakes the emulator up again, and it will execute until looping around to the next sleep() call, then same behavior, just goes into some weird limbo state. So as long as I keep pressing keys, the emulator makes background threads run. No key presses, it kind of just zones out and sort of forgets what i's supposed to be doing.

 

Also the emulator *normally* turns off the LCD when idle for a few seconds, but when it gets into this state, it seems to stop caring about idle-ness and the LCD is just permanently on.

 

Again, this only happens in like  30% of my tests, but I'm wondering if anyone else has experienced this. Is there any information I can give that would help debug this? I can reproduce this emulator state, but everything seems ok - I still have free memory, my thread count is consistent - not sure what's going on here,

 

Thanks,

Mark

Developer
Posts: 120
Registered: ‎07-16-2008
My Device: 9000

Re: Thread.sleep(1000) - sometimes hangs emulator!!

We have seen similar behavior where the simulator sometimes stops responding until a key is pressed or the trackwheel is rolled.  We have not been able to lock it down enough to reproduce it.  We'll take a look to see if it is happening in sleep statements.  We have seen it with several emulators, the only specific one I can recall is the 4.2.2.89 emulator.
Kurt Zettel | Chief Architect | Metova
www.metova.com
Developer
Posts: 70
Registered: ‎08-18-2008
My Device: Not Specified

Re: Thread.sleep(1000) - sometimes hangs emulator!!

 Thanks kzettel, at least I know other people are running into this. Have you noticed this happens on the actual handsets too by any chance? I'm ok if this is just an emulator bug, but if it has the chance of behaving the same way on an actual phone, that could definitely be problematic!

 

Thanks

Developer
Posts: 120
Registered: ‎07-16-2008
My Device: 9000

Re: Thread.sleep(1000) - sometimes hangs emulator!!

We have never seen it happen on actual devices.
Kurt Zettel | Chief Architect | Metova
www.metova.com