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.44 by dl, Mon Dec 22 16:25:20 2003 UTC vs.
Revision 1.45 by dl, Tue Dec 23 19:38:09 2003 UTC

# Line 6 | Line 6
6  
7   package java.util.concurrent;
8   import java.util.concurrent.locks.*;
9 import java.util.concurrent.atomic.AtomicInteger;
9   import java.util.*;
10  
11   /**
# Line 408 | Line 407 | public class ThreadPoolExecutor extends
407       */
408      private boolean addIfUnderCorePoolSize(Runnable firstTask) {
409          Thread t = null;
410 +        final ReentrantLock mainLock = this.mainLock;
411          mainLock.lock();
412          try {
413              if (poolSize < corePoolSize)
# Line 432 | Line 432 | public class ThreadPoolExecutor extends
432      private Runnable addIfUnderMaximumPoolSize(Runnable firstTask) {
433          Thread t = null;
434          Runnable next = null;
435 +        final ReentrantLock mainLock = this.mainLock;
436          mainLock.lock();
437          try {
438              if (poolSize < maximumPoolSize) {
# Line 508 | Line 509 | public class ThreadPoolExecutor extends
509       * Wake up all threads that might be waiting for tasks.
510       */
511      void interruptIdleWorkers() {
512 +        final ReentrantLock mainLock = this.mainLock;
513          mainLock.lock();
514          try {
515              for (Worker w : workers)
# Line 522 | Line 524 | public class ThreadPoolExecutor extends
524       * @param w the worker
525       */
526      private void workerDone(Worker w) {
527 +        final ReentrantLock mainLock = this.mainLock;
528          mainLock.lock();
529          try {
530              completedTaskCount += w.completedTasks;
# Line 557 | Line 560 | public class ThreadPoolExecutor extends
560  
561              // Either state is STOP, or state is SHUTDOWN and there is
562              // no work to do. So we can terminate.
560            runState = TERMINATED;
563              termination.signalAll();
564 +            runState = TERMINATED;
565              // fall through to call terminate() outside of lock.
566          } finally {
567              mainLock.unlock();
# Line 610 | Line 613 | public class ThreadPoolExecutor extends
613           * Interrupt thread if not running a task
614           */
615          void interruptIfIdle() {
616 +            final ReentrantLock runLock = this.runLock;
617              if (runLock.tryLock()) {
618                  try {
619                      thread.interrupt();
# Line 630 | Line 634 | public class ThreadPoolExecutor extends
634           * Run a single task between before/after methods.
635           */
636          private void runTask(Runnable task) {
637 +            final ReentrantLock runLock = this.runLock;
638              runLock.lock();
639              try {
640                  // Abort now if immediate cancel.  Otherwise, we have
# Line 880 | Line 885 | public class ThreadPoolExecutor extends
885              java.security.AccessController.checkPermission(shutdownPerm);
886  
887          boolean fullyTerminated = false;
888 +        final ReentrantLock mainLock = this.mainLock;
889          mainLock.lock();
890          try {
891              if (workers.size() > 0) {
# Line 928 | Line 934 | public class ThreadPoolExecutor extends
934              java.security.AccessController.checkPermission(shutdownPerm);
935  
936          boolean fullyTerminated = false;
937 +        final ReentrantLock mainLock = this.mainLock;
938          mainLock.lock();
939          try {
940              if (workers.size() > 0) {
# Line 985 | Line 992 | public class ThreadPoolExecutor extends
992  
993      public boolean awaitTermination(long timeout, TimeUnit unit)
994          throws InterruptedException {
995 +        final ReentrantLock mainLock = this.mainLock;
996          mainLock.lock();
997          try {
998              long nanos = unit.toNanos(timeout);
# Line 1132 | Line 1140 | public class ThreadPoolExecutor extends
1140      public void setCorePoolSize(int corePoolSize) {
1141          if (corePoolSize < 0)
1142              throw new IllegalArgumentException();
1143 +        final ReentrantLock mainLock = this.mainLock;
1144          mainLock.lock();
1145          try {
1146              int extra = this.corePoolSize - corePoolSize;
# Line 1203 | Line 1212 | public class ThreadPoolExecutor extends
1212      public void setMaximumPoolSize(int maximumPoolSize) {
1213          if (maximumPoolSize <= 0 || maximumPoolSize < corePoolSize)
1214              throw new IllegalArgumentException();
1215 +        final ReentrantLock mainLock = this.mainLock;
1216          mainLock.lock();
1217          try {
1218              int extra = this.maximumPoolSize - maximumPoolSize;
# Line 1280 | Line 1290 | public class ThreadPoolExecutor extends
1290       * @return the number of threads
1291       */
1292      public int getActiveCount() {
1293 +        final ReentrantLock mainLock = this.mainLock;
1294          mainLock.lock();
1295          try {
1296              int n = 0;
# Line 1300 | Line 1311 | public class ThreadPoolExecutor extends
1311       * @return the number of threads
1312       */
1313      public int getLargestPoolSize() {
1314 +        final ReentrantLock mainLock = this.mainLock;
1315          mainLock.lock();
1316          try {
1317              return largestPoolSize;
# Line 1318 | Line 1330 | public class ThreadPoolExecutor extends
1330       * @return the number of tasks
1331       */
1332      public long getTaskCount() {
1333 +        final ReentrantLock mainLock = this.mainLock;
1334          mainLock.lock();
1335          try {
1336              long n = completedTaskCount;
# Line 1342 | Line 1355 | public class ThreadPoolExecutor extends
1355       * @return the number of tasks
1356       */
1357      public long getCompletedTaskCount() {
1358 +        final ReentrantLock mainLock = this.mainLock;
1359          mainLock.lock();
1360          try {
1361              long n = completedTaskCount;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines