/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Internal class to manage all Timers using one thread.
* TimerQueue manages a queue of Timers. The Timers are chained
* together in a linked list sorted by the order in which they will expire.
*
* @author Dave Moore
* @author Igor Kushnirskiy
*/
{
new StringBuffer("TimerQueue.sharedInstanceKey");
new StringBuffer("TimerQueue.expiredTimersKey");
private volatile boolean running;
/* Lock object used in place of class object for synchronization.
* (4187686)
*/
/** Base of nanosecond timings, to avoid wrapping */
/**
* Constructor for TimerQueue.
*/
public TimerQueue() {
super();
// Now start the TimerQueue thread.
runningLock = new ReentrantLock();
}
synchronized (classLock) {
if (sharedInst == null) {
sharedInst = new TimerQueue();
}
return sharedInst;
}
}
void startIfNeeded() {
if (! running) {
runningLock.lock();
try {
final ThreadGroup threadGroup =
"TimerQueue");
timerThread.setDaemon(true);
timerThread.start();
return null;
}
});
running = true;
} finally {
}
}
}
try {
// If the Timer is already in the queue, then ignore the add.
if (! containsTimer(timer)) {
+ now()));
}
} finally {
}
}
try {
} finally {
}
}
try {
}
} finally {
}
}
try {
} finally {
}
}
public void run() {
runningLock.lock();
try {
while (running) {
try {
try {
if (delayedTimer != null) {
/*
* Timer is not removed after we get it from
* the queue and before the lock on the timer is
* acquired
*/
}
}
// Allow run other threads on systems without kernel threads
} catch (SecurityException ignore) {
} finally {
}
} catch (InterruptedException ie) {
// Shouldn't ignore InterruptedExceptions here, so AppContext
// is disposed gracefully, see 6799345 for details
break;
}
}
}
}
catch (ThreadDeath td) {
// Mark all the timers we contain as not being queued.
}
throw td;
} finally {
running = false;
}
}
boolean isFirst = true;
if (! isFirst) {
}
isFirst = false;
}
}
/**
* Returns nanosecond time offset by origin
*/
private static long now() {
}
// most of it copied from
// java.util.concurrent.ScheduledThreadPoolExecutor
/**
* Sequence number to break scheduling ties, and in turn to
* guarantee FIFO order among tied entries.
*/
/** Sequence number to break ties FIFO */
private final long sequenceNumber;
/** The time the task is enabled to execute in nanoTime units */
private volatile long time;
}
}
}
return timer;
}
if (other == this) { // compare zero ONLY if same object
return 0;
}
if (other instanceof DelayedTimer) {
if (diff < 0) {
return -1;
} else if (diff > 0) {
return 1;
} else if (sequenceNumber < x.sequenceNumber) {
return -1;
} else {
return 1;
}
}
return (d == 0) ? 0 : ((d < 0) ? -1 : 1);
}
}
}