Class CleanupRunnable
- java.lang.Object
-
- de.aristaflow.adept2.util.threading.CleanupRunnable
-
- All Implemented Interfaces:
Runnable
public class CleanupRunnable extends Object implements Runnable
A cleanup runnable executes a runnable (or several ones) and afterwards a special cleanup runnable finally after the first runnable. Problems occurring in the cleanup runnable will be logged to the designated logger (and added as suppressed to problems of the runnable if appropriate). This way exceptions from the first runnable will not be swallowed.
-
-
Field Summary
Fields Modifier and Type Field Description protected Runnable
cleanup
The cleanup runnable executed after the normal execution has terminated.protected Logger
logger
The logger for logging exceptions from the cleanup runnable.protected Runnable
runnable
The runnable executed normally.protected AtomicLong
sharingCount
A count for concurrently executed runnables sharing a common resource cleaned up incleanup
.
-
Constructor Summary
Constructors Constructor Description CleanupRunnable(Runnable runnable, Runnable cleanup, Logger logger)
Creates a new cleanup runnable executing the first runnable and the cleanup runnable finally after the first runnable.CleanupRunnable(Runnable runnable, AtomicLong sharingCount, Runnable cleanup, Logger logger)
Creates a new cleanup runnable executing the first runnable (and similar runnables concurrently) and the cleanup runnable finally right after the last of these runnables have terminated.
-
-
-
Field Detail
-
runnable
protected final Runnable runnable
The runnable executed normally.
-
sharingCount
protected final AtomicLong sharingCount
-
cleanup
protected final Runnable cleanup
The cleanup runnable executed after the normal execution has terminated.
-
logger
protected final Logger logger
The logger for logging exceptions from the cleanup runnable.
-
-
Constructor Detail
-
CleanupRunnable
public CleanupRunnable(Runnable runnable, Runnable cleanup, Logger logger)
Creates a new cleanup runnable executing the first runnable and the cleanup runnable finally after the first runnable. Problems occurring in the cleanup runnable will be logged to the designated logger.- Parameters:
runnable
- The runnable executed normally.cleanup
- The cleanup runnable executed after the normal execution has terminated.logger
- The logger for logging exceptions from the cleanup runnable.
-
CleanupRunnable
public CleanupRunnable(Runnable runnable, AtomicLong sharingCount, Runnable cleanup, Logger logger)
Creates a new cleanup runnable executing the first runnable (and similar runnables concurrently) and the cleanup runnable finally right after the last of these runnables have terminated. Problems occurring in the cleanup runnable will be logged to the designated logger,RuntimeException
s will be additionally added as suppressed to an exception of the first runnable if present.- Parameters:
runnable
- The runnable executed normally.sharingCount
- The count for synchronising similar runnables so thatcleanup
will not run before all runnables have terminated.cleanup
- The cleanup runnable executed after the designated runnables (and similar ones) have terminated.logger
- The logger for logging exceptions from the cleanup runnable.
-
-