|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.google.common.util.concurrent.AbstractExecutionThreadService
@Beta public abstract class AbstractExecutionThreadService
Base class for services that can implement startUp(), run() and
shutDown() methods. This class uses a single thread to execute the
service; consider AbstractService if you would like to manage any
threading manually.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.google.common.base.Service |
|---|
Service.State |
| Constructor Summary | |
|---|---|
AbstractExecutionThreadService()
|
|
| Method Summary | |
|---|---|
protected java.util.concurrent.Executor |
executor()
Returns the Executor that will be used to run this service. |
boolean |
isRunning()
|
protected abstract void |
run()
Run the service. |
protected void |
shutDown()
Stop the service. |
java.util.concurrent.Future<Service.State> |
start()
|
Service.State |
startAndWait()
|
protected void |
startUp()
Start the service. |
Service.State |
state()
|
java.util.concurrent.Future<Service.State> |
stop()
|
Service.State |
stopAndWait()
|
java.lang.String |
toString()
|
protected void |
triggerShutdown()
Invoked to request the service to stop. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public AbstractExecutionThreadService()
| Method Detail |
|---|
protected void startUp()
throws java.lang.Exception
java.lang.Exception
protected abstract void run()
throws java.lang.Exception
public void run() {
while (isRunning()) {
// perform a unit of work
}
}
...or you could respond to stop requests by implementing triggerShutdown(), which should cause run() to return.
java.lang.Exception
protected void shutDown()
throws java.lang.Exception
java.lang.Exceptionprotected void triggerShutdown()
protected java.util.concurrent.Executor executor()
Executor that will be used to run this service.
Subclasses may override this method to use a custom Executor, which
may configure its worker thread with a specific name, thread group or
priority. The returned executor's execute() method is called when this service is started, and should return
promptly.
public java.lang.String toString()
toString in class java.lang.Objectpublic final java.util.concurrent.Future<Service.State> start()
start in interface Servicepublic final Service.State startAndWait()
startAndWait in interface Servicepublic final boolean isRunning()
isRunning in interface Servicepublic final Service.State state()
state in interface Servicepublic final java.util.concurrent.Future<Service.State> stop()
stop in interface Servicepublic final Service.State stopAndWait()
stopAndWait in interface Service
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||