Warning: To avoid potential deadlock, operations that may block...

来源:互联网 发布:mac重装系统失败 编辑:程序博客网 时间:2024/06/07 23:39
Warning: To avoid potential deadlock, operations that may block, such as   networking, should be performed in a different thread than the   commandAction() handler.

         手机中,所有的MIDlet程序都是由Application Manager Software(AMS)管理的。当MIDlet初始化后,AMS就会调用MIDlet的startApp()方法,此时MIDlet就进入了Acitive状态。在JAVA ME中有些操作可能会导致程序堵塞,比如连接网络等。如果这些操作与主程序在同一个主线程中完成,那么由于堵塞会造成程序长时间无法返回,也就无法响应用户的其他操作了。所以,如果我们在commandAction()中进行了联网的操作,则会造成如上所述的情况。

        将调用操作的地方去new 一个Thread ,然后在Run方法里写调用函数:

new Thread(){public void run(){try{do();//调用操作}catch(Exception e){}}}.start();



 

原创粉丝点击