public abstract class Worker
extends java.lang.Object
implements java.lang.Runnable
Constructor and Description |
---|
Worker()
Default constructor.
|
Worker(KnockOffListener listener)
Constructor taking an initial knock off listener.
|
Modifier and Type | Method and Description |
---|---|
void |
addKnockOffListener(KnockOffListener listener)
Add a knock off listener.
|
protected abstract void |
execute()
Implement this in extending classes to do the work.
|
java.lang.Throwable |
getCaughtThrowable()
Get the throwable caught during work, if there happened one.
|
protected void |
informKnockOffListeners()
Call all knockoff listeners.
|
static void |
invokeInEventDispatchThread(java.lang.Runnable run)
Invoke in the AWT thread.
|
boolean |
isStopped()
Was the worker stopped?
|
void |
removeKnockOffListener(KnockOffListener listener)
Remove a knock off listener.
|
void |
rethrow()
This throws the caught exception if there occurred one.
|
void |
run()
When an object implementing interface
Runnable is used
to create a thread, starting the thread causes the object's
run method to be called in that separately executing
thread. |
void |
stop()
Removes all KnockOffListeners and sets the internal state to stopped.
|
void |
stop(boolean removeListeners)
Sets the internal state to stopped.
|
public Worker()
public Worker(@NotNull KnockOffListener listener)
listener
- knock off listenerpublic void run()
Runnable
is used
to create a thread, starting the thread causes the object's
run
method to be called in that separately executing
thread.
The general contract of the method run
is that it may
take any action whatsoever.
run
in interface java.lang.Runnable
Thread.run()
protected abstract void execute() throws java.lang.Throwable
java.lang.Throwable
- any exception thrown during work@Nullable public java.lang.Throwable getCaughtThrowable()
null
if there didn't occur anypublic void rethrow() throws java.lang.Throwable
java.lang.Throwable
- exception caught during execute of workpublic void addKnockOffListener(@NotNull KnockOffListener listener)
listener
- new listenerpublic void removeKnockOffListener(@NotNull KnockOffListener listener)
listener
- listener to removeprotected void informKnockOffListeners()
public void stop()
isStopped()
method regularly
and stop executing when it returns true.
This is a workaround for the broken behavior of the Thread.stop() method.
public void stop(boolean removeListeners)
isStopped()
method regularly
and stop executing when the stop state is true.
This is a workaround for the broken behavior of the Thread.stop() method.
removeListeners
- remove the listeners before stopping so they are not called when the worker finishes?
This is usually a good idea.public boolean isStopped()
true
.
This is a workaround for the broken behavior of the Thread.stop() method.
stop()
,
stop(boolean)
public static void invokeInEventDispatchThread(@NotNull java.lang.Runnable run)
run
- runnable which has to be invoked in the AWT event thread