public class CThread
extends java.lang.Thread
This class follows DbC(tm) methodology
(Wikipedia).
Where possible, contracts are implement with native's Java assert.
| Modifier and Type | Class and Description |
|---|---|
static class |
CThread.TerminationPolicy
Termination policy for thread created through current CThread's object.
|
| Constructor and Description |
|---|
CThread()
Constructor of a thread (direct replacement of Thread's constructor).
|
CThread(CRunnable ctarget)
Constructor of a thread (direct replacement of Thread's constructor).
|
CThread(CRunnable ctarget,
java.lang.String name)
Constructor of a thread (direct replacement of Thread's constructor).
|
CThread(java.lang.Runnable target)
Constructor of a thread (direct replacement of Thread's constructor).
|
CThread(java.lang.Runnable target,
java.lang.String name)
Constructor of a thread (direct replacement of Thread's constructor).
|
CThread(java.lang.String name)
Constructor of a thread (direct replacement of Thread's constructor).
|
CThread(java.lang.ThreadGroup group,
CRunnable ctarget)
Constructor of a thread (direct replacement of Thread's constructor).
|
CThread(java.lang.ThreadGroup group,
CRunnable ctarget,
java.lang.String name)
Constructor of a thread (direct replacement of Thread's constructor).
|
CThread(java.lang.ThreadGroup group,
CRunnable ctarget,
java.lang.String name,
long stackSize)
Constructor of a thread (direct replacement of Thread's constructor).
|
CThread(java.lang.ThreadGroup group,
java.lang.Runnable target)
Constructor of a thread (direct replacement of Thread's constructor).
|
CThread(java.lang.ThreadGroup group,
java.lang.Runnable target,
java.lang.String name)
Constructor of a thread (direct replacement of Thread's constructor).
|
CThread(java.lang.ThreadGroup group,
java.lang.Runnable target,
java.lang.String name,
long stackSize)
Constructor of a thread (direct replacement of Thread's constructor).
|
CThread(java.lang.ThreadGroup group,
java.lang.String name)
Constructor of a thread (direct replacement of Thread's constructor).
|
| Modifier and Type | Method and Description |
|---|---|
void |
ajoin()
Thread's join replacement, in which:
- the checked exception InterruptedException, is replaced by the unchecked exception ThreadInterruptedException. |
void |
ajoin(long millis)
Thread's join replacement, in which:
- the checked exception InterruptedException, is replaced by the unchecked exception ThreadInterruptedException. |
void |
ajoin(long millis,
int nanos)
Thread's join replacement, in which:
- the checked exception InterruptedException, is replaced by the unchecked exception ThreadInterruptedException. |
void |
arun()
The new thread program method.
|
static java.lang.Thread |
currentThread()
Current thread.
|
static long |
currentThreadID()
Current thread id.
|
long |
elapsedTime()
Elapsed time since
startTime. |
boolean |
failed()
Did thread failed (terminated with an exception) its execution?
Precondition:
terminated()
|
static void |
pause(int millis)
A thread safe pause service in which:
- the checked exception InterruptedException, is replaced by the unchecked exception ThreadInterruptedException. |
void |
run()
Replacement of default
run method to correctly handle exceptions,
and also to register thread execution start time. |
void |
setTerminationPolicy(CThread.TerminationPolicy terminationPolicy)
Define the thread's termination policy.
|
java.lang.Throwable |
sourceException()
Get the exception responsible for the thread's failure.
|
void |
start()
Replacement of default
start method (required to properly implement termination policy). |
void |
start(CThread.TerminationPolicy terminationPolicy)
A
start method imposing an explicit termination policy. |
boolean |
started()
Was request to start thread issued?
|
long |
startTime()
Time instance at which the thread has started execution.
|
boolean |
startTimeRegistered()
Has thread start time been registered?
|
boolean |
terminated()
Thread terminated?
|
CThread.TerminationPolicy |
terminationPolicy()
Current CThread object's termination policy.
|
activeCount, checkAccess, countStackFrames, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yieldpublic CThread()
public CThread(java.lang.Runnable target)
target != null - Runnable object referencetarget - Runnable to attach to threadpublic CThread(java.lang.String name)
name != null - String object referencename - String ID to attach to threadpublic CThread(java.lang.ThreadGroup group,
java.lang.String name)
group != null - ThreadGroup object referencename != null - String object referencegroup - thread's ThreadGroupname - String ID to attach to threadpublic CThread(java.lang.Runnable target,
java.lang.String name)
target != null - Runnable object referencename != null - String object referencetarget - Runnable to attach to threadname - String ID to attach to threadpublic CThread(java.lang.ThreadGroup group,
java.lang.Runnable target)
group != null - ThreadGroup object referencetarget != null - Runnable object referencegroup - thread's ThreadGrouptarget - Runnable to attach to threadpublic CThread(java.lang.ThreadGroup group,
java.lang.Runnable target,
java.lang.String name)
group != null - ThreadGroup object referencetarget != null - Runnable object referencename != null - String object referencegroup - thread's ThreadGrouptarget - Runnable to attach to threadname - String ID to attach to threadpublic CThread(java.lang.ThreadGroup group,
java.lang.Runnable target,
java.lang.String name,
long stackSize)
group != null - ThreadGroup object referencetarget != null - Runnable object referencename != null - String object referencestackSize > 0L - positive stack sizegroup - thread's ThreadGrouptarget - Runnable to attach to threadname - String ID to attach to threadstackSize - future thread's stack sizepublic CThread(CRunnable ctarget)
target != null - CRunnable object referencectarget - CRunnable to attach to threadpublic CThread(CRunnable ctarget, java.lang.String name)
target != null - CRunnable object referencename != null - String object referencectarget - CRunnable to attach to threadname - String ID to attach to threadpublic CThread(java.lang.ThreadGroup group,
CRunnable ctarget)
group != null - ThreadGroup object referencetarget != null - CRunnable object referencegroup - thread's ThreadGroupctarget - CRunnable to attach to threadpublic CThread(java.lang.ThreadGroup group,
CRunnable ctarget,
java.lang.String name)
group != null - ThreadGroup object referencetarget != null - CRunnable object referencename != null - String object referencegroup - thread's ThreadGroupctarget - CRunnable to attach to threadname - String ID to attach to threadpublic CThread(java.lang.ThreadGroup group,
CRunnable ctarget,
java.lang.String name,
long stackSize)
group != null - ThreadGroup object referencetarget != null - CRunnable object referencename != null - String object referencestackSize > 0L - positive stack sizegroup - thread's ThreadGroupctarget - CRunnable to attach to threadname - String ID to attach to threadstackSize - future thread's stack sizepublic void setTerminationPolicy(CThread.TerminationPolicy terminationPolicy)
TerminationPolicy.DEBUG: a thread failure causes a stack dump and the termination of the whole program (default behavior)TerminationPolicy.PROPAGATE: a thread failure causes the propagation of the failure to the ``parent'' thread (through the interrupt service)TerminationPolicy.IGNORE: a thread failure is ignored for the whole programTerminationPolicy.IGNORE_DEBUG: stack dumped to console, but thread failure is ignored for the whole program!started()terminationPolicy - policy (TerminationPolicy.DEBUG, TerminationPolicy.PROPAGATE, TerminationPolicy.IGNORE, TerminationPolicy.IGNORE_DEBUG)public CThread.TerminationPolicy terminationPolicy()
public void start(CThread.TerminationPolicy terminationPolicy)
start method imposing an explicit termination policy.
!started()terminationPolicy - policy (TerminationPolicy.DEBUG, TerminationPolicy.PROPAGATE, TerminationPolicy.IGNORE, TerminationPolicy.IGNORE_DEBUG)setTerminationPolicypublic void start()
start method (required to properly implement termination policy).
!started()start in class java.lang.Threadpublic boolean started()
public boolean terminated()
public boolean failed()
terminated()public java.lang.Throwable sourceException()
terminated() && failed() && terminationPolicy() == TerminationPolicy.PROPAGATEpublic void run()
run method to correctly handle exceptions,
and also to register thread execution start time.
The thread program must be defined in arun method.run in interface java.lang.Runnablerun in class java.lang.Threadpublic void arun()
public boolean startTimeRegistered()
public long startTime()
arun method either through CThread or CRunnable.
startTimeRegistered()public long elapsedTime()
startTime.
startTimeRegistered()public void ajoin()
throws ThreadInterruptedException
ThreadInterruptedExceptionpublic void ajoin(long millis)
throws ThreadInterruptedException
millis >= 0 - non negative timeoutmillis - timeout (in milliseconds)ThreadInterruptedExceptionpublic void ajoin(long millis,
int nanos)
throws ThreadInterruptedException
millis >= 0 - non negative timeoutnanos >= 0 - non negative timeoutmillis - timeout (in milliseconds)nanos - timeout (in nanoseconds)ThreadInterruptedExceptionpublic static void pause(int millis)
throws ThreadInterruptedException
millis >= 0 - non negative pause valuemillis - pause value (in milliseconds)ThreadInterruptedExceptionpublic static java.lang.Thread currentThread()
Thread objectpublic static long currentThreadID()