public abstract class Daemon extends Object implements Runnable
Main loop of daemon:
try { while (running) { canStop = true; // Get a notification, then execute the right reaction. try { // Get a request ... } catch (InterruptedException exc) { continue; } canStop = false; // executes the request ... } } finally { finish(); }
Modifier and Type | Field and Description |
---|---|
protected boolean |
canStop
Boolean variable used to stop the daemon properly.
|
private boolean |
daemon
The
daemon 's nature. |
protected ThreadGroup |
group
The group of this thread
|
protected org.objectweb.util.monolog.api.Logger |
logmon |
private String |
name
The
daemon 's name. |
protected int |
priority
The
priority that is assigned to the daemon. |
protected boolean |
running
Boolean variable used to stop the daemon properly.
|
protected Thread |
thread
The active component of this daemon.
|
Modifier | Constructor and Description |
---|---|
protected |
Daemon(String name)
Deprecated.
|
protected |
Daemon(String name,
org.objectweb.util.monolog.api.Logger logmon)
Allocates a new Daemon object.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
close()
Releases any resources attached to this daemon.
|
protected void |
finish() |
String |
getName()
Returns this
daemon 's name. |
void |
interrupt()
Interrupts this daemon.
|
boolean |
isCurrentThread()
Tests if the daemon's thread is the current one.
|
boolean |
isRunning()
Tests if this daemon is alive.
|
void |
setDaemon(boolean daemon)
Marks the daemon's thread as either a daemon thread a user thread.
|
void |
setName(String name) |
void |
setPriority(int newPriority)
Changes the priority of this daemon.
|
void |
setThreadGroup(ThreadGroup group)
Set the thread group to which this daemon's thread belongs.
|
protected abstract void |
shutdown()
Interrupts a thread that waits for long periods.
|
void |
start()
Causes this daemon to begin execution.
|
void |
stop()
Forces the daemon to stop executing.
|
String |
toString()
Returns a string representation of this daemon.
|
protected volatile boolean running
start
,
stop
protected volatile boolean canStop
running
variable between
each reaction)protected Thread thread
private String name
daemon
's name.private boolean daemon
daemon
's nature.protected int priority
priority
that is assigned to the daemon.protected ThreadGroup group
protected org.objectweb.util.monolog.api.Logger logmon
protected Daemon(String name)
name
- the name of the new Daemonprotected Daemon(String name, org.objectweb.util.monolog.api.Logger logmon)
name
- the name of the new Daemonlogmon
- inherited logging monitorpublic boolean isRunning()
public final String getName()
daemon
's name.daemon
's name.public String toString()
public void setDaemon(boolean daemon)
IllegalThreadStateException
- if this daemon was already active.public void setPriority(int newPriority)
Thread.setPriority
public void setThreadGroup(ThreadGroup group)
IllegalThreadStateException
- if this daemon was already active.public void start()
IllegalThreadStateException
- If the daemon was already started.protected abstract void close()
protected abstract void shutdown()
public void interrupt()
protected final void finish()
public void stop()
public boolean isCurrentThread()
public void setName(String name)
Copyright © 2015 ScalAgent D.T.. All Rights Reserved.