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

New Developer
Posts: 11
Registered: ‎12-06-2009
My Device: Not Specified
Accepted Solution

Thread synchronization

What is the best way to implement thread synchronization in BlackBerry?


I've a communication thread that handle the http communication with my server. The main thread put requests in a que and the communication thread handle them.

How can I 'wake' the communication thread when putting a request?


If there is no request from the main thread for a long time (1 sec) I also need to pool the server to check for updates.


I looked at GlobalEvent but didn't see how to make sure the eventOccur will happen in the communication thread.



Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Thread synchronization

When you synchronize, you are synchronizing on some object. (When you mark a method as synchronized, it's synchronizing on an instance of that class.) Typically, a thread will call wait() on the synchronization object to suspend itself until "something" happens. That "something" is usually another thread completing some work and then calling notify() or notifyAll() on the synchronization object, which will wake up the waiting thread.


Sun's Java tutorial on concurrency has a nice explanation of all this. You can also search the web for Java implementations of the producer/consumer pattern.


For the specific application of timed polling, take a look at the java.util.TimerTask class.

Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.