views:

1556

answers:

4

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.

A: 

The only issue I can think of is discussed in the answer to another stackoverflow question.

Richard
That's more of a generic threading issue thats relevant to any platform, I'm referring to the specific implementation of threads in the BlackBerry JVM.
roryf
A: 

I've done a fair bit of programming for both the BlackBerry and desktop java, and I'm not aware of any differences in the threading model.

stak
+1  A: 

Two quirks I found in the blackberry forums:

  1. Vector is not thread safe.
  2. If you are creating a native blackberry CLDC app, a static is not necessarily a singleton over the VM.
Jacques René Mesrine
+2  A: 

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.

kozen