IdlingScheduledThreadPoolExecutor


public class IdlingScheduledThreadPoolExecutor extends ScheduledThreadPoolExecutor implements IdlingResource


A ScheduledThreadPoolExecutor that can be registered as an IdlingResource with Espresso.

Overrides parent methods to monitor threads starting, and finishing execution. Uses to track number of active tasks.

Summary

Public constructors

IdlingScheduledThreadPoolExecutor(
    String resourceName,
    int corePoolSize,
    ThreadFactory threadFactory
)

Creates a new IdlingScheduledThreadPoolExecutor with the given initial parameters.

IdlingScheduledThreadPoolExecutor(
    String resourceName,
    int corePoolSize,
    ThreadFactory threadFactory,
    boolean debugCounting
)

Creates a new IdlingScheduledThreadPoolExecutor with the given initial parameters.

Public methods

String

Returns the name of the resources (used for logging and idempotency of registration).

boolean

Returns true if resource is currently idle.

void

Registers the given ResourceCallback with the resource.

ScheduledFuture<V>
<V> schedule(Callable<V> callable, long delay, TimeUnit unit)
ScheduledFuture<Object>
schedule(Runnable command, long delay, TimeUnit unit)

Protected methods

void
void
void

Inherited methods

From java.util.concurrent.AbstractExecutorService
List<Future<T>>
<T> invokeAll(Collection<Callable<T>> tasks)
T
<T> invokeAny(Collection<Callable<T>> tasks)
RunnableFuture<T>
<T> newTaskFor(Runnable runnable, T value)
From java.util.concurrent.ScheduledThreadPoolExecutor
RunnableScheduledFuture<V>
void
execute(Runnable command)
boolean
boolean
BlockingQueue<Runnable>
boolean
ScheduledFuture<Object>
scheduleAtFixedRate(
    Runnable command,
    long initialDelay,
    long period,
    TimeUnit unit
)
ScheduledFuture<Object>
scheduleWithFixedDelay(
    Runnable command,
    long initialDelay,
    long delay,
    TimeUnit unit
)
void
void
void
setRemoveOnCancelPolicy(boolean value)
void
List<Runnable>
Future<Object>
Future<T>
<T> submit(Runnable task, T result)
From java.util.concurrent.ThreadPoolExecutor
void
allowCoreThreadTimeOut(boolean value)
boolean
boolean
awaitTermination(long timeout, TimeUnit unit)
void

This method is deprecated.

int
long
int
long
int
int
int
RejectedExecutionHandler
long
ThreadFactory
boolean
boolean
boolean
int
boolean
void
boolean
void
setCorePoolSize(int corePoolSize)
void
setKeepAliveTime(long time, TimeUnit unit)
void
setMaximumPoolSize(int maximumPoolSize)
void
void
String

Public constructors

IdlingScheduledThreadPoolExecutor

public IdlingScheduledThreadPoolExecutor(
    String resourceName,
    int corePoolSize,
    ThreadFactory threadFactory
)

Creates a new IdlingScheduledThreadPoolExecutor with the given initial parameters.

Parameters
String resourceName

the name of the executor (used for logging and idempotency of registration).

int corePoolSize

the number of threads to keep in the pool, even if they are idle, unless allowCoreThreadTimeOut is set.

ThreadFactory threadFactory

the factory to use when the executor creates a new thread.

IdlingScheduledThreadPoolExecutor

public IdlingScheduledThreadPoolExecutor(
    String resourceName,
    int corePoolSize,
    ThreadFactory threadFactory,
    boolean debugCounting
)

Creates a new IdlingScheduledThreadPoolExecutor with the given initial parameters.

Parameters
String resourceName

the name of the executor (used for logging and idempotency of registration).

int corePoolSize

the number of threads to keep in the pool, even if they are idle, unless allowCoreThreadTimeOut is set.

ThreadFactory threadFactory

the factory to use when the executor creates a new thread.

boolean debugCounting

if true increment &decrement calls will print trace information to logs.

Public methods

getName

public String getName()

Returns the name of the resources (used for logging and idempotency of registration).

isIdleNow

public boolean isIdleNow()

Returns true if resource is currently idle. Espresso will always call this method from the main thread, therefore it should be non-blocking and return immediately.

registerIdleTransitionCallback

public void registerIdleTransitionCallback(
    IdlingResource.ResourceCallback callback
)

Registers the given ResourceCallback with the resource. Espresso will call this method:

  • with its implementation of ResourceCallback so it can be notified asynchronously that your resource is idle
  • from the main thread, but you are free to execute the callback's onTransitionToIdle from any thread
  • once (when it is initially given a reference to your IdlingResource)

You only need to call this upon transition from busy to idle - if the resource is already idle when the method is called invoking the call back is optional and has no significant impact.

schedule

public ScheduledFuture<V> <V> schedule(Callable<V> callable, long delay, TimeUnit unit)

schedule

public ScheduledFuture<Objectschedule(Runnable command, long delay, TimeUnit unit)

Protected methods

afterExecute

protected void afterExecute(Runnable r, Throwable t)

beforeExecute

protected void beforeExecute(Thread t, Runnable r)

terminated

protected void terminated()