Пример #1
0
 /**
  * * 鍒濆鍖栫嚎绋嬫睜
  *
  * @param threads
  */
 private static void resizeWorkThreads(int threads) {
   // System.out.println("threads:"+threads);
   if (threads > 0) {
     for (int i = 0; i < threads; i++) {
       WorkThread wt = new WorkThread();
       wt.setPriority(Thread.MIN_PRIORITY);
       wt.start();
       pooledWorkThreads.addElement(wt);
     }
   } else {
     for (int i = 0; i < 0 - threads; i++) {
       int count = pooledWorkThreads.size();
       if (count > 0) {
         WorkThread wt = (WorkThread) pooledWorkThreads.elementAt(count - 1);
         pooledWorkThreads.removeElementAt(count - 1);
         while (!wt.IsIdle()) {
           try {
             Thread.sleep(0);
           } catch (InterruptedException e) {
             // TODO Auto-generated catch block
             // e.printStackTrace();
           }
         }
         wt.exit();
       }
     }
   }
 }
Пример #2
0
  /** 娓呯┖绾跨▼姹� */
  public static void Destroy() {
    while (!isIdle()) {
      try {
        Thread.sleep(0);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    for (int i = 0; i < maxWorkThreads; i++) {
      WorkThread wt = (WorkThread) pooledWorkThreads.elementAt(i);
      wt.exit();
    }
    pooledWorkThreads.removeAllElements();
  }