src/share/classes/com/sun/corba/se/impl/orbutil/threadpool/WorkQueueImpl.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -109,28 +109,27 @@
// class
MonitoredObject getMonitoredObject() {
return workqueueMonitoredObject;
}
- public void addWork(Work work) {
- synchronized (this) {
+ public synchronized void addWork(Work work) {
workItemsAdded++;
work.setEnqueueTime(System.currentTimeMillis());
theWorkQueue.addLast(work);
((ThreadPoolImpl)workerThreadPool).notifyForAvailableWork(this);
}
- }
- Work requestWork(long waitTime)
- throws TimeoutException, InterruptedException
+ synchronized Work requestWork(long waitTime) throws TimeoutException, InterruptedException
{
Work workItem;
- synchronized (this) {
+ ((ThreadPoolImpl)workerThreadPool).incrementNumberOfAvailableThreads();
+
if (theWorkQueue.size() != 0) {
workItem = (Work)theWorkQueue.removeFirst();
totalTimeInQueue += System.currentTimeMillis() - workItem.getEnqueueTime();
workItemsDequeued++;
+ ((ThreadPoolImpl)workerThreadPool).decrementNumberOfAvailableThreads();
return workItem;
}
try {
@@ -143,24 +142,26 @@
if (theWorkQueue.size() != 0) {
workItem = (Work)theWorkQueue.removeFirst();
totalTimeInQueue += System.currentTimeMillis() - workItem.getEnqueueTime();
workItemsDequeued++;
+ ((ThreadPoolImpl)workerThreadPool).decrementNumberOfAvailableThreads();
return workItem;
}
remainingWaitTime = finishTime - System.currentTimeMillis();
} while (remainingWaitTime > 0);
+ ((ThreadPoolImpl)workerThreadPool).decrementNumberOfAvailableThreads();
throw new TimeoutException();
} catch (InterruptedException ie) {
+ ((ThreadPoolImpl)workerThreadPool).decrementNumberOfAvailableThreads();
throw ie;
}
}
- }
public void setThreadPool(ThreadPool workerThreadPool) {
this.workerThreadPool = workerThreadPool;
}