posts - 24,  comments - 25,  trackbacks - 0

          DataThread.java控制其他線程是否運行:

          public class DataThread extends Thread
          {
              
          public void run()
              
          {
                  SendThread send 
          = null;
                  Thread SendThread 
          = new Thread(send);
                  
          while (true)
                  
          {
                      
          try
                      
          {
                          
          if ("0158".equals(WmsFormatter.toParamTime(new Date()).substring(04)))
                          
          {
                              
          if (SendThread.isAlive())
                              
          {
                                  send.close();
                              }

                          }


                          
          if (!hostSendThread.isAlive())
                              
          {
                                  send 
          = new SendThread();
                                  SendThread 
          = new Thread(send);
                                  SendThread.start();
                              }

                          Thread.sleep(
          50000);
                      }
          catch (Exception e)
                      
          {
                       
          try {
                              e.printStackTrace();
                                  
          continue;
                             }
           catch (Exception e1) {
                                   
          continue;
                             }

                      }

                  }

              }


              
          public static void main(String[] args)
              
          {
                  
          new DataThread().start();
              }


          SendThread.java
          public class SendThread implements Runnable
          {
              
          private boolean flag = true;

              
          public void close()
              
          {
                  flag 
          = false;
              }


              
          public void run()
              
          {
                  
          while (flag == true)
                  
          {
                      
                  }

              }

          }
          posted on 2011-04-19 11:13 Jarry 閱讀(184) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 龙门县| 甘德县| 新建县| 山西省| 赤城县| 常德市| 法库县| 沾益县| 汽车| 长宁县| 双辽市| 泸定县| 阿拉尔市| 禹城市| 仁化县| 昭平县| 漯河市| 防城港市| 赤峰市| 清徐县| 德格县| 湛江市| 太仓市| 河西区| 景洪市| 黄山市| 安龙县| 定远县| 宣汉县| 文成县| 林甸县| 呈贡县| 五寨县| 罗平县| 榆社县| 明光市| 台州市| 遵义市| 碌曲县| 朝阳区| 望都县|