|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcz.cuni.utils.RunnableTemplate
public class RunnableTemplate
This class shouldn't be altered or instancied - it's only example / template where you can learn how to implement runnable classes and what is a good practice when doing so.
Field Summary | |
---|---|
private Flag<java.lang.Boolean> |
communicationAlive
Always keep track whether the communication is up and running! |
private java.util.concurrent.CountDownLatch |
communicationLatch
If you want to start communication with somebody - always use this object. |
private java.lang.Thread |
thread
If instance has been started (via runThread()) - then this is initialized. |
private Flag<java.lang.Boolean> |
threadAlive
Flag which tells us wether threadIsAlive - initialize the flag at the beggining of the run() and drops it as the last command of the run(). |
Constructor Summary | |
---|---|
RunnableTemplate()
|
Method Summary | |
---|---|
protected void |
communicationDied()
Mark the communication as dead. |
protected void |
communicationSettedUp()
Mark the communication is setted up. |
Flag<java.lang.Boolean> |
getCommunicationAliveFlag()
|
java.lang.Thread |
getThread()
Get thread of the instance, if not isThreadAlive() then it returns null. |
Flag<java.lang.Boolean> |
getThreadAliveFlag()
|
boolean |
isCommunicationAlive()
Returns state of the communication. |
boolean |
isThreadAlive()
Returns state of the thread. |
void |
run()
Is called internaly from runThread() ... this class shouldn't be run via Thread.run(object). |
java.lang.Thread |
runThread()
This method should be used to run() this class in a new thread. |
boolean |
waitForCommunication()
This operation is guaranteed to block until communication is setted up. |
boolean |
waitForCommunication(long timeOut,
java.util.concurrent.TimeUnit unit)
This operation is guaranteed to block until communication is setted up. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private Flag<java.lang.Boolean> threadAlive
private java.util.concurrent.CountDownLatch communicationLatch
private Flag<java.lang.Boolean> communicationAlive
private java.lang.Thread thread
Constructor Detail |
---|
public RunnableTemplate()
Method Detail |
---|
public Flag<java.lang.Boolean> getThreadAliveFlag()
public boolean isThreadAlive()
public Flag<java.lang.Boolean> getCommunicationAliveFlag()
public boolean isCommunicationAlive()
public boolean waitForCommunication()
public boolean waitForCommunication(long timeOut, java.util.concurrent.TimeUnit unit)
protected void communicationSettedUp()
protected void communicationDied()
public java.lang.Thread runThread()
public java.lang.Thread getThread()
public void run()
run
in interface java.lang.Runnable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |