ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ThreadPoolExecutor.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ThreadPoolExecutor.java (file contents):
Revision 1.49 by dl, Sun Jan 4 00:56:48 2004 UTC vs.
Revision 1.50 by dl, Sun Jan 11 23:19:55 2004 UTC

# Line 396 | Line 396 | public class ThreadPoolExecutor extends
396  
397      /**
398       * Create and start a new thread running firstTask as its first
399 <     * task, only if less than corePoolSize threads are running.
399 >     * task, only if fewer than corePoolSize threads are running.
400       * @param firstTask the task the new thread should run first (or
401       * null if none)
402       * @return true if successful.
# Line 418 | Line 418 | public class ThreadPoolExecutor extends
418      }
419  
420      /**
421 <     * Create and start a new thread only if less than maximumPoolSize
421 >     * Create and start a new thread only if fewer than maximumPoolSize
422       * threads are running.  The new thread runs as its first task the
423       * next task in queue, or if there is none, the given task.
424       * @param firstTask the task the new thread should run first (or
# Line 487 | Line 487 | public class ThreadPoolExecutor extends
487                  // Wait for one, re-checking state upon interruption
488                  try {
489                      return workQueue.take();
490 <                }
491 <                catch(InterruptedException ignore) {
492 <                }
490 >                } catch(InterruptedException ignore) {}
491                  break;
492              }
493  
# Line 664 | Line 662 | public class ThreadPoolExecutor extends
662           */
663          public void run() {
664              try {
665 <                for (;;) {
666 <                    Runnable task;
667 <                    if (firstTask != null) {
670 <                        task = firstTask;
671 <                        firstTask = null;
672 <                    } else {
673 <                        task = getTask();
674 <                        if (task == null)
675 <                            break;
676 <                    }
665 >                Runnable task = firstTask;
666 >                firstTask = null;
667 >                while (task != null || (task = getTask()) != null) {
668                      runTask(task);
669                      task = null; // unnecessary but can help GC
670                  }
# Line 749 | Line 740 | public class ThreadPoolExecutor extends
740                                TimeUnit unit,
741                                BlockingQueue<Runnable> workQueue,
742                                ThreadFactory threadFactory) {
752
743          this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,
744               threadFactory, defaultHandler);
745      }
# Line 885 | Line 875 | public class ThreadPoolExecutor extends
875          mainLock.lock();
876          try {
877              if (workers.size() > 0) {
878 <                // Check if caller can modify worker threads.
879 <                // This might not be true even if passed above check,
880 <                // if the SecurityManager treats some threads specially.
878 >                // Check if caller can modify worker threads.  This
879 >                // might not be true even if passed above check, if
880 >                // the SecurityManager treats some threads specially.
881                  if (security != null) {
882                      for (Worker w: workers)
883                          security.checkAccess(w.thread);
# Line 901 | Line 891 | public class ThreadPoolExecutor extends
891                      for (Worker w: workers)
892                          w.interruptIfIdle();
893                  } catch(SecurityException se) {
894 <                    // If SecurityManager allows above checks, but then
895 <                    // unexpectedly throws exception when interrupting
896 <                    // threads (which it ought not do), back out as
897 <                    // cleanly as we can. -Some threads may have been
898 <                    // killed but we remain in non-shutdown state.
894 >                    // If SecurityManager allows above checks, but
895 >                    // then unexpectedly throws exception when
896 >                    // interrupting threads (which it ought not do),
897 >                    // back out as cleanly as we can. Some threads may
898 >                    // have been killed but we remain in non-shutdown
899 >                    // state.
900                      runState = state;
901                      throw se;
902                  }
# Line 960 | Line 951 | public class ThreadPoolExecutor extends
951          }
952          if (fullyTerminated)
953              terminated();
963        
954          return Arrays.asList(workQueue.toArray(EMPTY_RUNNABLE_ARRAY));
955      }
956  
# Line 988 | Line 978 | public class ThreadPoolExecutor extends
978  
979      public boolean awaitTermination(long timeout, TimeUnit unit)
980          throws InterruptedException {
981 +        long nanos = unit.toNanos(timeout);
982          final ReentrantLock mainLock = this.mainLock;
983          mainLock.lock();
984          try {
994            long nanos = unit.toNanos(timeout);
985              for (;;) {
986                  if (runState == TERMINATED)
987                      return true;
# Line 1102 | Line 1092 | public class ThreadPoolExecutor extends
1092       * However, this method may fail to remove tasks in
1093       * the presence of interference by other threads.
1094       */
1105
1095      public void purge() {
1096          // Fail if we encounter interference during traversal
1097          try {
# Line 1405 | Line 1394 | public class ThreadPoolExecutor extends
1394       * is discarded.
1395       */
1396     public static class CallerRunsPolicy implements RejectedExecutionHandler {
1408
1397          /**
1398           * Creates a <tt>CallerRunsPolicy</tt>.
1399           */
# Line 1429 | Line 1417 | public class ThreadPoolExecutor extends
1417       * <tt>RejectedExecutionException</tt>.
1418       */
1419      public static class AbortPolicy implements RejectedExecutionHandler {
1432
1420          /**
1421           * Creates an <tt>AbortPolicy</tt>.
1422           */
# Line 1451 | Line 1438 | public class ThreadPoolExecutor extends
1438       * rejected task.
1439       */
1440      public static class DiscardPolicy implements RejectedExecutionHandler {
1454
1441          /**
1442           * Creates <tt>DiscardPolicy</tt>.
1443           */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines