com.addc.commons.shutdown.Terminator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of addc-base Show documentation
Show all versions of addc-base Show documentation
The addc-base library supplies classes for creating UUIDs, converting between types, outputting byte arrays with different formats,
support for Julian dates, delay generators, parsing properties files and support for I18N.
package com.addc.commons.shutdown;
/**
* The Terminator supplies a method to terminate a {@link Stoppable} in the
* background.
*
*/
public final class Terminator {
/**
* The TerminatorThread actually stops the stoppable in the background
*/
private static class TerminatorThread extends Thread {
private final Stoppable stoppable;
/**
* Create a new TerminatorThread
*
* @param stoppable
* The stoppable to terminate
*/
public TerminatorThread(Stoppable stoppable) {
super();
this.stoppable= stoppable;
}
@Override
public void run() {
stoppable.shutdown();
}
}
/**
* Terminate the {@link Stoppable} in the background.
*
* @param stoppable
* the {@link Stoppable} to terminate
*/
public static void terminate(final Stoppable stoppable) {
TerminatorThread terminator= new TerminatorThread(stoppable);
terminator.start();
}
private Terminator() {
}
}