Reputation: 981
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?
Upvotes: 1
Views: 168
Reputation: 28168
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 this 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, this book is a must read.
Upvotes: 1