com.sleepycat.je.utilint
Class DaemonThread

java.lang.Object
  extended by com.sleepycat.je.utilint.DaemonThread
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
Checkpointer, Cleaner, Evictor, INCompressor

public abstract class DaemonThread
extends Object
implements Runnable

A daemon thread.


Field Summary
protected  String name
           
protected  int nWakeupRequests
           
protected  Set workQueue
           
protected  Latch workQueueLatch
           
 
Constructor Summary
DaemonThread(long waitTime, String name, EnvironmentImpl env)
           
 
Method Summary
 void addToQueue(Object o)
           
 void addToQueueAlreadyLatched(Collection c)
           
 int getNWakeupRequests()
          For unit testing.
 int getQueueSize()
           
 Thread getThread()
          For testing.
 boolean isRunning()
          Returns whether the onWakeup method is currently executing.
protected  boolean isShutdownRequested()
          Returns whether shutdown has been requested.
protected  int nDeadlockRetries()
          Returns the number of retries to perform when Deadlock Exceptions occur.
protected abstract  void onWakeup()
          onWakeup is synchronized to ensure that multiple invocations of the DaemonThread aren't made.
 void requestShutdown()
           
 void run()
           
 void runOrPause(boolean run)
          If run is true, starts the thread if not started or unpauses it if already started; if run is false, pauses the thread if started or does nothing if not started.
 void shutdown()
          Requests shutdown and calls join() to wait for the thread to stop.
 String toString()
           
 void wakeup()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected String name

workQueue

protected Set workQueue

workQueueLatch

protected Latch workQueueLatch

nWakeupRequests

protected int nWakeupRequests
Constructor Detail

DaemonThread

public DaemonThread(long waitTime,
                    String name,
                    EnvironmentImpl env)
Method Detail

getThread

public Thread getThread()
For testing.


runOrPause

public void runOrPause(boolean run)
If run is true, starts the thread if not started or unpauses it if already started; if run is false, pauses the thread if started or does nothing if not started.


requestShutdown

public void requestShutdown()

shutdown

public void shutdown()
Requests shutdown and calls join() to wait for the thread to stop.


toString

public String toString()
Overrides:
toString in class Object

addToQueue

public void addToQueue(Object o)
                throws DatabaseException
Throws:
DatabaseException

getQueueSize

public int getQueueSize()
                 throws DatabaseException
Throws:
DatabaseException

addToQueueAlreadyLatched

public void addToQueueAlreadyLatched(Collection c)
                              throws DatabaseException
Throws:
DatabaseException

wakeup

public void wakeup()

run

public void run()
Specified by:
run in interface Runnable

nDeadlockRetries

protected int nDeadlockRetries()
                        throws DatabaseException
Returns the number of retries to perform when Deadlock Exceptions occur.

Throws:
DatabaseException

onWakeup

protected abstract void onWakeup()
                          throws DatabaseException
onWakeup is synchronized to ensure that multiple invocations of the DaemonThread aren't made. isRunnable must be called from within onWakeup to avoid having the following sequence: Thread A: isRunnable() => true, Thread B: isRunnable() => true, Thread A: onWakeup() starts Thread B: waits for monitor on thread to call onWakeup() Thread A: onWakeup() completes rendering isRunnable() predicate false Thread B: onWakeup() starts, but isRunnable predicate is now false

Throws:
DatabaseException

isShutdownRequested

protected boolean isShutdownRequested()
Returns whether shutdown has been requested. This method should be used to to terminate daemon loops.


isRunning

public boolean isRunning()
Returns whether the onWakeup method is currently executing. This is only an approximation and is used to avoid unnecessary wakeups.


getNWakeupRequests

public int getNWakeupRequests()
For unit testing.



Copyright 2004-2005 Sleepycat, Inc. All Rights Reserved.