org.skife.clocked
Class ClockedExecutorService

java.lang.Object
  extended by java.util.concurrent.AbstractExecutorService
      extended by java.util.concurrent.ThreadPoolExecutor
          extended by org.skife.clocked.ClockedExecutorService
All Implemented Interfaces:
Closeable, Executor, ExecutorService, ScheduledExecutorService

public class ClockedExecutorService
extends ThreadPoolExecutor
implements ScheduledExecutorService, Closeable

NOT INTENDED FOR USE OUTSIDE CAREFULLY CONTROLLED TESTS

ScheduledExecutorService implementation designed for deterministic testing. It runs off an internal clock which must be manually advanced via the advance(long, java.util.concurrent.TimeUnit) method.

Additionally, for recurring scheduled tasks, there is a guarantee that the task will nly be called once for each call to advance(...). This is important to note as it rather violates the normal contracts, but is very useful for testing.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
 
Constructor Summary
ClockedExecutorService()
           
ClockedExecutorService(int corePoolSize)
           
 
Method Summary
 Future<?> advance(long time, TimeUnit unit)
           
 void close()
           
<V> ScheduledFuture<V>
schedule(Callable<V> callable, long delay, TimeUnit unit)
           
 ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)
           
 ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
           
 ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
           
 
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
afterExecute, allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, execute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated
 
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow, submit, submit, submit
 
Methods inherited from interface java.util.concurrent.Executor
execute
 

Constructor Detail

ClockedExecutorService

public ClockedExecutorService(int corePoolSize)

ClockedExecutorService

public ClockedExecutorService()
Method Detail

advance

public Future<?> advance(long time,
                         TimeUnit unit)
                  throws ExecutionException,
                         InterruptedException
Throws:
ExecutionException
InterruptedException

schedule

public ScheduledFuture<?> schedule(Runnable command,
                                   long delay,
                                   TimeUnit unit)
Specified by:
schedule in interface ScheduledExecutorService

schedule

public <V> ScheduledFuture<V> schedule(Callable<V> callable,
                                       long delay,
                                       TimeUnit unit)
Specified by:
schedule in interface ScheduledExecutorService

scheduleAtFixedRate

public ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
                                              long initialDelay,
                                              long period,
                                              TimeUnit unit)
Specified by:
scheduleAtFixedRate in interface ScheduledExecutorService

scheduleWithFixedDelay

public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command,
                                                 long initialDelay,
                                                 long delay,
                                                 TimeUnit unit)
Specified by:
scheduleWithFixedDelay in interface ScheduledExecutorService

close

public void close()
Specified by:
close in interface Closeable


Copyright © 2014. All rights reserved.