activemq-cpp-3.6.0
|
A Thread is a concurrent unit of execution. More...
#include <src/main/decaf/lang/Thread.h>
Data Structures | |
class | UncaughtExceptionHandler |
Interface for handlers invoked when a Thread abruptly terminates due to an uncaught exception. More... |
Public Types | |
enum | State { NEW = 0, RUNNABLE = 1, BLOCKED = 2, WAITING = 3, TIMED_WAITING = 4, SLEEPING = 5, TERMINATED = 6 } |
Represents the various states that the Thread can be in during its lifetime. More... |
Public Member Functions | |
Thread () | |
Constructs a new Thread. | |
Thread (Runnable *task) | |
Constructs a new Thread with the given target Runnable task. | |
Thread (const std::string &name) | |
Constructs a new Thread with the given name. | |
Thread (Runnable *task, const std::string &name) | |
Constructs a new Thread with the given target Runnable task and name. | |
Thread (Runnable *task, const std::string &name, long long stackSize) | |
Constructs a new Thread with the given target Runnable task and name. | |
virtual | ~Thread () |
virtual void | start () |
Creates a system thread and starts it in a joinable mode. | |
virtual void | join () |
Forces the Current Thread to wait until the thread exits. | |
virtual void | join (long long millisecs) |
Forces the Current Thread to wait until the thread exits. | |
virtual void | join (long long millisecs, int nanos) |
Forces the Current Thread to wait until the thread exits. | |
virtual void | run () |
Default implementation of the run method - does nothing. | |
long long | getId () const |
Obtains the Thread Id of the current thread, this value is OS specific but is guaranteed not to change for the lifetime of this thread. | |
std::string | getName () const |
Returns the Thread's assigned name. | |
void | setName (const std::string &name) |
Sets the name of the Thread to the new Name given by the argument name | |
int | getPriority () const |
Gets the currently set priority for this Thread. | |
void | setPriority (int value) |
Sets the current Thread's priority to the newly specified value. | |
UncaughtExceptionHandler * | getUncaughtExceptionHandler () const |
Set the handler invoked when this thread abruptly terminates due to an uncaught exception. | |
void | setUncaughtExceptionHandler (UncaughtExceptionHandler *handler) |
Set the handler invoked when this thread abruptly terminates due to an uncaught exception. | |
std::string | toString () const |
Returns a string that describes the Thread. | |
bool | isAlive () const |
Returns true if the Thread is alive, meaning it has been started and has not yet died. | |
Thread::State | getState () const |
Returns the currently set State of this Thread. | |
void | interrupt () |
Interrupts the Thread if it is blocked and in an interruptible state. | |
bool | isInterrupted () const |
Returns but does not clear the state of this Thread's interrupted flag. | |
![]() | |
virtual | ~Runnable () |
Static Public Member Functions | |
static void | sleep (long long millisecs) |
Causes the currently executing thread to halt execution for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers. | |
static void | sleep (long long millisecs, int nanos) |
Causes the currently executing thread to halt execution for the specified number of milliseconds plus any additionally specified nanoseconds given, subject to the precision and accuracy of system timers and schedulers. | |
static void | yield () |
Causes the currently executing thread object to temporarily pause and allow other threads to execute. | |
static Thread * | currentThread () |
Returns a pointer to the currently executing thread object. | |
static bool | interrupted () |
Returns whether the thread has been interrupted and clears the interrupted state such that a subsequent call will return false unless an interrupt occurs between the two calls. | |
static UncaughtExceptionHandler * | getDefaultUncaughtExceptionHandler () |
Set the default handler invoked when a thread abruptly terminates due to an uncaught exception, this handler is used only if there is no other handler defined for the Thread. | |
static void | setDefaultUncaughtExceptionHandler (UncaughtExceptionHandler *handler) |
Set the default handler invoked when a thread abruptly terminates due to an uncaught exception,. |
Static Public Attributes | |
static const int | MIN_PRIORITY = 1 |
The minimum priority that a thread can have. | |
static const int | NORM_PRIORITY = 5 |
The default priority that a thread is given at create time. | |
static const int | MAX_PRIORITY = 10 |
The maximum priority that a thread can have. |
Friends | |
class | decaf::internal::util::concurrent::Threading |
class | ThreadGroup |
A Thread is a concurrent unit of execution.
It has its own call stack for methods being invoked, their arguments and local variables. Each process has at least one main Thread running when it is started; typically, there are several others for housekeeping. The application might decide to launch additional Threads for specific purposes.
Threads in the same process interact and synchronize by the use of shared objects and monitors associated with these objects.
There are basically two main ways of having a Thread execute application code. One is providing a new class that extends Thread and overriding its run() method. The other is providing a new Thread instance with a Runnable object during its creation. In both cases, the start() method must be called to actually execute the new Thread.
Each Thread has an integer priority that basically determines the amount of CPU time the Thread gets. It can be set using the setPriority(int) method.
Represents the various states that the Thread can be in during its lifetime.
NEW |
Before a Thread is started it exists in this State. |
RUNNABLE |
While a Thread is running and is not blocked it is in this State. |
BLOCKED |
A Thread that is waiting to acquire a lock is in this state. |
WAITING |
A Thread that is waiting for another Thread to perform an action is in this state. |
TIMED_WAITING |
A Thread that is waiting for another Thread to perform an action up to a specified time interval is in this state. |
SLEEPING |
A Thread that is blocked in a Sleep call is in this state. |
TERMINATED |
A Thread whose run method has exited is in this state. |
decaf::lang::Thread::Thread | ( | ) |
Constructs a new Thread.
This constructor has the same effect as Thread( NULL, NULL, GIVEN_NAME ), where GIVEN_NAME is a newly generated name. When no name is given the name is automatically generated and are of the form "Thread-"+n, where n is an integer.
decaf::lang::Thread::Thread | ( | Runnable * | task | ) |
decaf::lang::Thread::Thread | ( | const std::string & | name | ) |
Constructs a new Thread with the given name.
This constructor has the same effect as Thread( NULL, NULL, GIVEN_NAME ), where GIVEN_NAME is a newly generated name. When no name is given the name is automatically generated and are of the form "Thread-"+n, where n is an integer.
name | the name to assign to this Thread. |
Constructs a new Thread with the given target Runnable task and name.
This constructor has the same effect as Thread( NULL, task, GIVEN_NAME ), where GIVEN_NAME is a newly generated name. When no name is given the name is automatically generated and are of the form "Thread-"+n, where n is an integer.
Constructs a new Thread with the given target Runnable task and name.
This constructor has the same effect as Thread( NULL, task, GIVEN_NAME ), where GIVEN_NAME is a newly generated name. When no name is given the name is automatically generated and are of the form "Thread-"+n, where n is an integer.
The stack size option is platform independent and may have no effect on the newly created thread on some systems. If the value given is invalid on the system a RuntimeException is thrown, the stack size can be invalid if it is outside the allowed range or doesn't match the size of the system page size on some system.
|
virtual |
|
static |
|
static |
Set the default handler invoked when a thread abruptly terminates due to an uncaught exception, this handler is used only if there is no other handler defined for the Thread.
This method will return NULL if no handler has ever been set, or the handler is cleared via a call to the setDefaultUncaughtExceptionHandler method will NULL as the value of the handler argument.
long long decaf::lang::Thread::getId | ( | ) | const |
std::string decaf::lang::Thread::getName | ( | ) | const |
int decaf::lang::Thread::getPriority | ( | ) | const |
Thread::State decaf::lang::Thread::getState | ( | ) | const |
UncaughtExceptionHandler* decaf::lang::Thread::getUncaughtExceptionHandler | ( | ) | const |
Set the handler invoked when this thread abruptly terminates due to an uncaught exception.
void decaf::lang::Thread::interrupt | ( | ) |
Interrupts the Thread if it is blocked and in an interruptible state.
When the thread is in one of its own join or sleep methods or blocked by a call to a monitor or mutex wait call it will clear its interrupted flag and and an InterruptedException will be thrown.
In other cases the thread's interrupted status will be set and an instance of an InterruptedException may be thrown.
If the thread is not alive when this method is called there is no affect.
|
static |
Returns whether the thread has been interrupted and clears the interrupted state such that a subsequent call will return false unless an interrupt occurs between the two calls.
bool decaf::lang::Thread::isAlive | ( | ) | const |
Returns true if the Thread is alive, meaning it has been started and has not yet died.
bool decaf::lang::Thread::isInterrupted | ( | ) | const |
Returns but does not clear the state of this Thread's interrupted flag.
|
virtual |
Forces the Current Thread to wait until the thread exits.
InterruptedException | if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown. |
|
virtual |
Forces the Current Thread to wait until the thread exits.
millisecs | the time in Milliseconds before the thread resumes |
IllegalArgumentException | if the milliseconds parameter is negative. |
InterruptedException | if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown. |
|
virtual |
Forces the Current Thread to wait until the thread exits.
millisecs | the time in Milliseconds before the thread resumes |
nanos | 0-999999 extra nanoseconds to sleep. |
IllegalArgumentException | if the nanoseconds parameter is out of range or the milliseconds paramter is negative. |
InterruptedException | if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown. |
|
virtual |
Default implementation of the run method - does nothing.
Implements decaf::lang::Runnable.
Reimplemented in activemq::transport::mock::InternalCommandListener.
|
static |
Set the default handler invoked when a thread abruptly terminates due to an uncaught exception,.
handler | The UncaightExceptionHandler to invoke when a Thread terminates due to an uncaught exception, passing NULL clears this value. |
void decaf::lang::Thread::setName | ( | const std::string & | name | ) |
void decaf::lang::Thread::setPriority | ( | int | value | ) |
Sets the current Thread's priority to the newly specified value.
The given value must be within the range Thread::MIN_PRIORITY and Thread::MAX_PRIORITY.
value | the new priority value to assign to this Thread. |
IllegalArgumentException | if the value is out of range. |
void decaf::lang::Thread::setUncaughtExceptionHandler | ( | UncaughtExceptionHandler * | handler | ) |
Set the handler invoked when this thread abruptly terminates due to an uncaught exception.
handler | the UncaightExceptionHandler to invoke when the Thread terminates due to an uncaught exception. |
|
static |
Causes the currently executing thread to halt execution for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers.
Note that this method is a static method that applies to the calling thread and not to the thread object.
millisecs | time in milliseconds to halt execution. |
IllegalArgumentException | if the milliseconds parameter is negative. |
InterruptedException | if the Thread was interrupted while sleeping. |
|
static |
Causes the currently executing thread to halt execution for the specified number of milliseconds plus any additionally specified nanoseconds given, subject to the precision and accuracy of system timers and schedulers.
Note that this method is a static method that applies to the calling thread and not to the thread object.
millisecs | time in milliseconds to halt execution. |
nanos | 0-999999 extra nanoseconds to sleep. |
IllegalArgumentException | if the nanoseconds parameter is out of range or the milliseconds paramter is negative. |
InterruptedException | if the Thread was interrupted while sleeping. |
|
virtual |
Creates a system thread and starts it in a joinable mode.
Upon creation, the run() method of either this object or the provided Runnable object will be invoked in the context of this thread.
IllegalThreadStateException | if the thread has already been started. |
RuntimeException | if the Thread cannot be created for some reason. |
std::string decaf::lang::Thread::toString | ( | ) | const |
|
static |
Causes the currently executing thread object to temporarily pause and allow other threads to execute.
|
friend |
|
friend |
|
static |
The maximum priority that a thread can have.
|
static |
The minimum priority that a thread can have.
|
static |
The default priority that a thread is given at create time.