posts - 24,  comments - 25,  trackbacks - 0

          DataThread.java控制其他線程是否運(yùn)行:

          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
          主站蜘蛛池模板: 嘉义县| 五大连池市| 顺平县| 扎囊县| 灵寿县| 襄垣县| 曲靖市| 霞浦县| 治县。| 周至县| 乌兰浩特市| 新龙县| 河东区| 逊克县| 通州市| 杭锦后旗| 邵武市| 安达市| 霍林郭勒市| 东山县| 泰来县| 化隆| 乌什县| 迁西县| 田东县| 永城市| 西丰县| 金秀| 嵊州市| 库尔勒市| 神木县| 远安县| 丰县| 乐业县| 唐海县| 上栗县| 津市市| 南宁市| 黄龙县| 吴忠市| 铜川市|