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 閱讀(192) 評(píng)論(0)  編輯  收藏 所屬分類: Java

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 太原市| 达拉特旗| 榆林市| 瑞安市| 东辽县| 开鲁县| 镇坪县| 铜梁县| 彭山县| 汨罗市| 呼和浩特市| 濮阳市| 霍林郭勒市| 萨迦县| 麦盖提县| 嘉荫县| 冷水江市| 平利县| 迁安市| 印江| 东至县| 黑山县| 张家港市| 高阳县| 遵化市| 兴化市| 鸡泽县| 宁河县| 千阳县| 广德县| 大城县| 岑溪市| 和林格尔县| 桑日县| 徐汇区| 绥宁县| 威宁| 进贤县| 凯里市| 运城市| 海伦市|