BlackBerry threading model

ぃ、小莉子 提交于 2019-12-02 19:37:26
kozen

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:

  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.

The differences aren't in the Threading model but the way in you use them and as The initial post said, You can't use a ui thread for network connections or you can't use a network connection for updating the ui.

There are a lot of differences in this matter between what you called desktop java an blackberry java... believe me!

Richard

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!