Verified Owner
Top Description Fields Constructors Methods
org.jabref.logic.util

public Class DelayTaskThrottler

extends Object
Class Inheritance
Imports
java.util.concurrent.Callable, .RejectedExecutionException, .ScheduledFuture, .ScheduledThreadPoolExecutor, .TimeUnit, org.slf4j.Logger, .LoggerFactory

This class allows to throttle a list of tasks. Use case: you have an event that occurs often, and every time you want to invoke the same task. However, if a lot of events happen in a relatively short time span, then only one task should be invoked.

Implementation Note

Once schedule(Runnable) is called, the task is delayed for a given time span. If during this time, schedule(Runnable) is called again, then the original task is canceled and the new one scheduled.

Field Summary

Modifier and TypeField and Description
private int
private final ScheduledThreadPoolExecutor
private static final Logger
private ScheduledFuture<?>

Constructor Summary

AccessConstructor and Description
public
DelayTaskThrottler(int
delay in milliseconds
delay
)

Method Summary

Modifier and TypeMethod and Description
public void
cancel()

Cancel scheduled Runnable gracefully

public void
execute(Runnable command)

Execute scheduled Runnable early

public ScheduledFuture<?>
schedule(Runnable command)

public <T> ScheduledFuture<?>
scheduleTask(Callable<?> command)

public void
shutdown()

Shuts everything down.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delayback to summary
private int delay
executorback to summary
private final ScheduledThreadPoolExecutor executor
LOGGERback to summary
private static final Logger LOGGER
scheduledTaskback to summary
private ScheduledFuture<?> scheduledTask

Constructor Detail

DelayTaskThrottlerback to summary
public DelayTaskThrottler(int delay)
Parameters
delay:int

delay in milliseconds

Method Detail

cancelback to summary
public void cancel()

Cancel scheduled Runnable gracefully

executeback to summary
public void execute(Runnable command)

Execute scheduled Runnable early

scheduleback to summary
public ScheduledFuture<?> schedule(Runnable command)
scheduleTaskback to summary
public <T> ScheduledFuture<?> scheduleTask(Callable<?> command)
shutdownback to summary
public void shutdown()

Shuts everything down. Upon termination, this method returns.