org.shlublu.javax.lang
Class BasicThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--org.shlublu.javax.lang.BasicThread
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
IOStreamCrossedConnector

public abstract class BasicThread
extends java.lang.Thread

Creation : 29 oct 2001 Convenience class dedicated to implement threads. The run() method is defined to call startup, iteration, cleanup/crashcleanup methods. Those threads can be stopped by calling a method.

Since:
0.1

Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
BasicThread()
          Empty ctor
BasicThread(java.lang.String strName)
          Ctor
 
Method Summary
protected abstract  void doCleanup()
          This method is called just after the last mainloop turn.
protected abstract  void doCrashCleanup()
          This method is called in case of mainloop crash.
protected abstract  void doIteration()
          This method is called each mainloop turn.
protected abstract  void doStartup()
          This method is called just before the first mainloop turn.
 java.lang.Exception getCrashReason()
          Get the caught Exception in case of crash, null otherwise
 void run()
          Run implementation :
try { doStartup(); while (bAlive) { doIteration(); yield(); } doCleanup(); } catch (Exception e) { eCauseOfDeath = e; doCrashCleanup(); }
 void stopJob()
          Stop this thread
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicThread

public BasicThread()
Empty ctor

BasicThread

public BasicThread(java.lang.String strName)
Ctor
Parameters:
String - strName the name of tyhe thread
Method Detail

run

public final void run()
Run implementation :
 try
 {
	 	doStartup();
	 	
	 	while (bAlive)
	 	{
	 		doIteration();
	 						
	 		yield();
	 	}
	 	
 		doCleanup();
 }
 catch (Exception e)
 {
	 	eCauseOfDeath = e;
	 	
 		doCrashCleanup();
 }
 
Overrides:
run in class java.lang.Thread

doIteration

protected abstract void doIteration()
                             throws java.lang.Exception
This method is called each mainloop turn.
To be implemented by subclasses
Throws:
java.lang.Exception - all exceptions are caught by run()
See Also:
run()

doStartup

protected abstract void doStartup()
                           throws java.lang.Exception
This method is called just before the first mainloop turn.
To be implemented by subclasses
Throws:
java.lang.Exception - all exceptions are caught by run()
See Also:
run()

doCleanup

protected abstract void doCleanup()
                           throws java.lang.Exception
This method is called just after the last mainloop turn.
To be implemented by subclasses
Throws:
java.lang.Exception - all exceptions are caught by run()
See Also:
run(), stopJob()

doCrashCleanup

protected abstract void doCrashCleanup()
This method is called in case of mainloop crash. No exception is thrown because this method is called in a catch. Its goal is to cleanup but not to throw an Exception again.
To be implemented by subclasses
See Also:
run()

stopJob

public void stopJob()
Stop this thread

getCrashReason

public final java.lang.Exception getCrashReason()
Get the caught Exception in case of crash, null otherwise