Note when shutdown has been requested and refuse to accept further units from
that time, rather than from the time that the shutdown is actually processed. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2525 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -144,8 +144,8 @@ public class Invoker extends LoopingThread
|
|||||||
*/
|
*/
|
||||||
public void postUnit (Unit unit)
|
public void postUnit (Unit unit)
|
||||||
{
|
{
|
||||||
if (!isRunning()) {
|
if (!shutdownRequested()) {
|
||||||
throw new IllegalStateException("Invoker has been shutdown");
|
throw new IllegalStateException("Cannot post units to shutdown invoker.");
|
||||||
}
|
}
|
||||||
// note the time
|
// note the time
|
||||||
unit.queueStamp = System.currentTimeMillis();
|
unit.queueStamp = System.currentTimeMillis();
|
||||||
@@ -211,6 +211,7 @@ public class Invoker extends LoopingThread
|
|||||||
@Override
|
@Override
|
||||||
public void shutdown ()
|
public void shutdown ()
|
||||||
{
|
{
|
||||||
|
_shutdownRequested = true;
|
||||||
_queue.append(new Unit() {
|
_queue.append(new Unit() {
|
||||||
@Override public boolean invoke () {
|
@Override public boolean invoke () {
|
||||||
_running = false;
|
_running = false;
|
||||||
@@ -231,6 +232,15 @@ public class Invoker extends LoopingThread
|
|||||||
_profileBucketCount = bucketCount;
|
_profileBucketCount = bucketCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if {@link #shutdown} has been called. {@link #isRunning} may still return true
|
||||||
|
* until the shutdown unit is reached and processed by the invoker thread.
|
||||||
|
*/
|
||||||
|
protected boolean shutdownRequested ()
|
||||||
|
{
|
||||||
|
return _shutdownRequested;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called before we process an invoker unit.
|
* Called before we process an invoker unit.
|
||||||
*
|
*
|
||||||
@@ -328,6 +338,10 @@ public class Invoker extends LoopingThread
|
|||||||
/** The duration of time after which we consider a unit to be delinquent and log a warning. */
|
/** The duration of time after which we consider a unit to be delinquent and log a warning. */
|
||||||
protected static long _defaultLongThreshold = 500L;
|
protected static long _defaultLongThreshold = 500L;
|
||||||
|
|
||||||
|
/** True after {@link #shutdown} has been called but before the invoker has finished processing
|
||||||
|
* any remaining queued units. */
|
||||||
|
protected volatile boolean _shutdownRequested;
|
||||||
|
|
||||||
/** Whether or not to track invoker unit performance. */
|
/** Whether or not to track invoker unit performance. */
|
||||||
protected static final boolean PERF_TRACK = true;
|
protected static final boolean PERF_TRACK = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user