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 |
|
/** |
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) |
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) { |
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) |
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; |
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(); |
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(); |
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 |
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) { |
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) { |
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); |
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; |
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; |
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; |
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; |
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; |
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; |