您的位置:首页 > 运维架构

Warning: To avoid potential deadlock, operations that may block, such as

2009-11-11 12:16 423 查看
Warning: To avoid potential deadlock, operations that may block, such as
networking, should be performed in a different thread than the
commandAction() handler.

开发j2me出现的网络连接异常,该异常的意思就是说: 如果你没有使用一个单独的线程来做连接的话,那么该程序就可能出现 潜在的死锁,操作可能会阻塞...

解决办法: 为连接开辟一个新的线程:

方法一:

    

    Runnable runnable = new Runnable

    {
       public void run()

       {
    do();
     }
   }
   new Thread(runnable ).start();

   在类中加入方法do()
   在这个方法中完成网络连接的工作。

  

 方法二:

    new Thread(){
      public void run(){
  do();
      }
    }.start();

注意:在 run 内部使用外部的 this ,也就是外部的对象不能直接 this, 您可以用 外部的类名.this
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐