Skip to content

Commit 6402796

Browse files
hansonrhansonr
authored andcommitted
tidying up
- awaitTermination disabled
1 parent b53627f commit 6402796

File tree

1 file changed

+64
-41
lines changed

1 file changed

+64
-41
lines changed

sources/net.sf.j2s.java.core/src/java/util/concurrent/ThreadPoolExecutor.java

Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@
3434
*/
3535

3636
package java.util.concurrent;
37+
import java.util.ArrayList;
38+
import java.util.ConcurrentModificationException;
39+
import java.util.HashSet;
40+
import java.util.Iterator;
41+
import java.util.List;
42+
import java.util.concurrent.atomic.AtomicInteger;
3743
import java.util.concurrent.locks.AbstractQueuedSynchronizer;
38-
import java.util.concurrent.locks.Condition;
3944
import java.util.concurrent.locks.ReentrantLock;
4045

4146
import javajs.async.SwingJSUtils;
42-
43-
import java.util.concurrent.atomic.AtomicInteger;
44-
import java.util.*;
47+
import swingjs.JSUtil;
4548

4649
// BH SwingJS removed primary securityManager checks
4750
/**
@@ -466,10 +469,10 @@ private void decrementWorkerCount() {
466469
*/
467470
private final HashSet<Worker> workers = new HashSet<Worker>();
468471

469-
/**
470-
* Wait condition to support awaitTermination
471-
*/
472-
private final Condition termination = mainLock.newCondition();
472+
// /**
473+
// * Wait condition to support awaitTermination
474+
// */
475+
// private final Condition termination = mainLock.newCondition();
473476

474477
/**
475478
* Tracks largest attained pool size. Accessed only under
@@ -616,7 +619,8 @@ private final class Worker
616619
}
617620

618621
/** Delegates main run loop to outer runWorker */
619-
public void run() {
622+
@Override
623+
public void run() {
620624
runWorker(this);
621625
}
622626

@@ -625,19 +629,22 @@ public void run() {
625629
// The value 0 represents the unlocked state.
626630
// The value 1 represents the locked state.
627631

628-
protected boolean isHeldExclusively() {
632+
@Override
633+
protected boolean isHeldExclusively() {
629634
return getState() != 0;
630635
}
631636

632-
protected boolean tryAcquire(int unused) {
637+
@Override
638+
protected boolean tryAcquire(int unused) {
633639
if (compareAndSetState(0, 1)) {
634640
setExclusiveOwnerThread(Thread.currentThread());
635641
return true;
636642
}
637643
return false;
638644
}
639645

640-
protected boolean tryRelease(int unused) {
646+
@Override
647+
protected boolean tryRelease(int unused) {
641648
setExclusiveOwnerThread(null);
642649
setState(0);
643650
return true;
@@ -1150,7 +1157,8 @@ final void runWorker(Worker w) {
11501157
wt.interrupt();
11511158
// run on event queue
11521159
SwingJSUtils.StateHelper.delayedRun(100, new Runnable() {
1153-
public void run() {
1160+
@Override
1161+
public void run() {
11541162
try {
11551163
beforeExecute(wt, task);
11561164
Throwable thrown = null;
@@ -1349,7 +1357,8 @@ public ThreadPoolExecutor(int corePoolSize,
13491357
* cannot be accepted for execution
13501358
* @throws NullPointerException if {@code command} is null
13511359
*/
1352-
public void execute(Runnable command) {
1360+
@Override
1361+
public void execute(Runnable command) {
13531362
if (command == null)
13541363
throw new NullPointerException();
13551364
/*
@@ -1396,7 +1405,8 @@ else if (!addWorker(command, false))
13961405
*
13971406
* @throws SecurityException {@inheritDoc}
13981407
*/
1399-
public void shutdown() {
1408+
@Override
1409+
public void shutdown() {
14001410
// final ReentrantLock mainLock = this.mainLock;
14011411
// mainLock.lock();
14021412
// try {
@@ -1424,7 +1434,8 @@ public void shutdown() {
14241434
*
14251435
* @throws SecurityException {@inheritDoc}
14261436
*/
1427-
public List<Runnable> shutdownNow() {
1437+
@Override
1438+
public List<Runnable> shutdownNow() {
14281439
List<Runnable> tasks;
14291440
final ReentrantLock mainLock = this.mainLock;
14301441
mainLock.lock();
@@ -1440,7 +1451,8 @@ public List<Runnable> shutdownNow() {
14401451
return tasks;
14411452
}
14421453

1443-
public boolean isShutdown() {
1454+
@Override
1455+
public boolean isShutdown() {
14441456
return stopped;//! isRunning(ctl.get());
14451457
}
14461458

@@ -1456,37 +1468,44 @@ public boolean isShutdown() {
14561468
* @return true if terminating but not yet terminated
14571469
*/
14581470
public boolean isTerminating() {
1459-
int c = ctl.get();
1460-
return ! isRunning(c) && runStateLessThan(c, TERMINATED);
1471+
return false;
1472+
// int c = ctl.get();
1473+
// return ! isRunning(c) && runStateLessThan(c, TERMINATED);
14611474
}
14621475

1463-
public boolean isTerminated() {
1464-
return runStateAtLeast(ctl.get(), TERMINATED);
1476+
@Override
1477+
public boolean isTerminated() {
1478+
return stopped;
1479+
// return runStateAtLeast(ctl.get(), TERMINATED);
14651480
}
14661481

1467-
public boolean awaitTermination(long timeout, TimeUnit unit)
1482+
@Override
1483+
public boolean awaitTermination(long timeout, TimeUnit unit)
14681484
throws InterruptedException {
1469-
long nanos = unit.toNanos(timeout);
1470-
final ReentrantLock mainLock = this.mainLock;
1471-
mainLock.lock();
1472-
try {
1473-
for (;;) {
1474-
if (runStateAtLeast(ctl.get(), TERMINATED))
1475-
return true;
1476-
if (nanos <= 0)
1477-
return false;
1478-
nanos = termination.awaitNanos(nanos);
1479-
}
1480-
} finally {
1481-
mainLock.unlock();
1482-
}
1485+
JSUtil.notImplemented("ThreadPoolExecutor.awaitTermination -- Sorry, can't wait in JavaScript");
1486+
return false;
1487+
// long nanos = unit.toNanos(timeout);
1488+
// final ReentrantLock mainLock = this.mainLock;
1489+
// mainLock.lock();
1490+
// try {
1491+
// for (;;) {
1492+
// if (runStateAtLeast(ctl.get(), TERMINATED))
1493+
// return true;
1494+
// if (nanos <= 0)
1495+
// return false;
1496+
// nanos = termination.awaitNanos(nanos);
1497+
// }
1498+
// } finally {
1499+
// mainLock.unlock();
1500+
// }
14831501
}
14841502

14851503
/**
14861504
* Invokes {@code shutdown} when this executor is no longer
14871505
* referenced and it has no threads.
14881506
*/
1489-
protected void finalize() {
1507+
@Override
1508+
protected void finalize() {
14901509
shutdown();
14911510
}
14921511

@@ -1981,7 +2000,8 @@ public CallerRunsPolicy() { }
19812000
* @param r the runnable task requested to be executed
19822001
* @param e the executor attempting to execute this task
19832002
*/
1984-
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
2003+
@Override
2004+
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
19852005
if (!e.isShutdown()) {
19862006
r.run();
19872007
}
@@ -2005,7 +2025,8 @@ public AbortPolicy() { }
20052025
* @param e the executor attempting to execute this task
20062026
* @throws RejectedExecutionException always.
20072027
*/
2008-
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
2028+
@Override
2029+
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
20092030
throw new RejectedExecutionException();
20102031
}
20112032
}
@@ -2026,7 +2047,8 @@ public DiscardPolicy() { }
20262047
* @param r the runnable task requested to be executed
20272048
* @param e the executor attempting to execute this task
20282049
*/
2029-
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
2050+
@Override
2051+
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
20302052
}
20312053
}
20322054

@@ -2050,7 +2072,8 @@ public DiscardOldestPolicy() { }
20502072
* @param r the runnable task requested to be executed
20512073
* @param e the executor attempting to execute this task
20522074
*/
2053-
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
2075+
@Override
2076+
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
20542077
if (!e.isShutdown()) {
20552078
e.getQueue().poll();
20562079
e.execute(r);

0 commit comments

Comments
 (0)