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

BlackBerry Themes & Animated Graphics

Reply
Contributor
Posts: 34
Registered: ‎05-02-2013
My Device: 9700
My Carrier: Idea

BlackBerry multithreading

I want to know about the threading concept in BlackBerry.

In Android we have async task or handlers to communicate. Is there something similar available in BlackBerry? How do two threads communicate? How do you pass data from a background thread to the UI thread?

Highlighted
Contributor
Posts: 18
Registered: ‎05-15-2013
My Device: 9700
My Carrier: 919909743132

Re: BlackBerry multithreading

Concurrency is not a trivial thing. It's really difficult to craft a Thread-safe solution. In Blackberry Java the situation is even worse, as only JavaME Threading APIs are available, meaning you can't use all the Java SE high level classes (like executors, locks, collections, etc).

My advice would be not to try to port Android's AsyncTask or any other high level concurrency-related class on your own, since very likely you'll make mistakes (unless you are well versed in concurrent programming). I myself would avoid it as much as possible. Instead keep the concurrent code as simple and small as you can. Most of the times all you need is to refresh the GUI from a worker thread. This can be done easily with UiApplication.invokeLater and UiApplication.invokeAndWait, and you don't need to write concurrent code at all.

If you want to learn more about concurrency, I'd start with http://docs.oracle.com/javase/tutorial/essential/concurrency/ tutorial by Oracle. It's aimed for JavaSE, but almost the first half is useful for JavaME as well. In case you want to learn more advanced concurrent programming, http://www.amazon.com/dp/0321349601/?tag=stackoverfl08-20 book is a must read.