I've read a lot of comments mention in passing that the BlackBerry threading model deviates from the Java standard and can cause issues, but no amount of googling has enlightened me on what this means exactly.
I've been developing a fairly large business application for the BlackBerry and, although I don't really have any previous experience with Java multi-threaded applications, haven't come across any issue that we've been able to blame on threading, other than what we caused ourselves.
Can someone describe exactly how the BlackBerry threading model is different, and how I as a developer should take that into account? Obviously any links on the topic would also be great.
1.UI
User interface operations always need to run in the UI thread. To execute such functions like LabelField.setText("foo");
you need to do:
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run(){
myLabelField.setText("foo");
myLabelField.setDirty(true);
}
});
Pretty easy, huh?
2.Network Network operation should never run within the UI thread. To do such things do:
new Thread(){
public void run(){
HttpConnection hc =
(HttpConnection)Connector.open("http://www.stackoverflow.com");
}
}.start();
These two main principle are very important. You should always take care of in which thread you are operating.
Two quirks I found in the blackberry forums:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With