黑莓线程模型 [英] BlackBerry threading model

查看:100
本文介绍了黑莓线程模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过很多评论轻描淡写地说,黑莓线程模型从Java标准不符,并可能导致的问题,但没有谷歌搜索量已经照亮我的这是什么意思究竟提了。

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.

我一直在开发黑莓一个相当大的业务应用,虽然我真的不具备Java多线程应用程序的任何previous经验,还没有碰到过,我们已经什么问题能怪线程,其他​​比我们自己造成的。

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
用户界面操作的总是需要在UI线程中运行。为了执行这样的功能,如 LabelField.setText(富); 你需要做的:

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容易,是吧?

Pretty easy, huh?

2.Network
网络操作应的从不 UI线程中运行。做这种事情要做:

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.

这篇关于黑莓线程模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆