groovyx.gpars.scheduler
Class Scheduler

java.lang.Object
  extended by groovyx.gpars.scheduler.Scheduler
All Implemented Interfaces:
Pool

public final class Scheduler
extends java.lang.Object
implements Pool

Prototype of self-regulated thread pooled scheduler

Self regulation happened according to following rules - worker thread, which had nothing to do 10 seconds dies - if no tasks were taken for processing during last 0.5sec new worker starts


Nested Class Summary
private  class Scheduler.WatchdogThread
           
private  class Scheduler.WorkerThread
           
 
Field Summary
private  long lastTaskPoke
           
private static long POKE_INTERVAL
           
private  java.util.concurrent.BlockingQueue<java.lang.Runnable> queue
           
private  long schedulerTime
           
(package private) static java.lang.RuntimeException TERMINATE
           
private  boolean terminating
           
private  java.util.concurrent.atomic.AtomicInteger threadCount
           
 
Fields inherited from interface groovyx.gpars.scheduler.Pool
POOL_SIZE_MUST_BE_A_POSITIVE_NUMBER, UNCAUGHT_EXCEPTION_OCCURRED_IN_ACTOR_POOL
 
Constructor Summary
Scheduler()
           
Scheduler(int coreSize)
           
 
Method Summary
 void execute(java.lang.Runnable task)
          schedules a new task for processing with the pool
 int getPoolSize()
          Retrieves the current thread pool size
 java.lang.Runnable loop(java.lang.Runnable operation)
           
 void resetDefaultSize()
          Sets the pool size to the default
 void resize(int poolSize)
          Resizes the thread pool to the specified value
 void shutdown()
          Gently stops the pool
private  void startNewThread()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queue

private final java.util.concurrent.BlockingQueue<java.lang.Runnable> queue

threadCount

private final java.util.concurrent.atomic.AtomicInteger threadCount

lastTaskPoke

private volatile long lastTaskPoke

schedulerTime

private volatile long schedulerTime

terminating

private volatile boolean terminating

TERMINATE

static final java.lang.RuntimeException TERMINATE

POKE_INTERVAL

private static final long POKE_INTERVAL
See Also:
Constant Field Values
Constructor Detail

Scheduler

public Scheduler()

Scheduler

public Scheduler(int coreSize)
Method Detail

execute

public void execute(java.lang.Runnable task)
Description copied from interface: Pool
schedules a new task for processing with the pool

Specified by:
execute in interface Pool
Parameters:
task - The task to schedule

loop

public java.lang.Runnable loop(java.lang.Runnable operation)

startNewThread

private void startNewThread()

resize

public void resize(int poolSize)
Description copied from interface: Pool
Resizes the thread pool to the specified value

Specified by:
resize in interface Pool
Parameters:
poolSize - The new pool size

resetDefaultSize

public void resetDefaultSize()
Description copied from interface: Pool
Sets the pool size to the default

Specified by:
resetDefaultSize in interface Pool

getPoolSize

public int getPoolSize()
Retrieves the current thread pool size

Specified by:
getPoolSize in interface Pool
Returns:
The pool size

shutdown

public void shutdown()
Description copied from interface: Pool
Gently stops the pool

Specified by:
shutdown in interface Pool

Copyright © 2008–2012 Václav Pech. All Rights Reserved.