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 閱讀(192) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 资源县| 余姚市| 富宁县| 乐陵市| 兴宁市| 盘山县| 留坝县| 历史| 余江县| 依安县| 廊坊市| 金门县| 永州市| 长顺县| 凤山县| 清丰县| 荣成市| 平邑县| 方山县| 遵义市| 桑植县| 凤阳县| 漠河县| 景东| 乐至县| 麻城市| 阜城县| 札达县| 仪陇县| 霍林郭勒市| 永顺县| 扶余县| 井研县| 霸州市| 嘉祥县| 隆安县| 勐海县| 纳雍县| 宜川县| 崇信县| 高雄市|