activemq-cpp-3.4.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. | |
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, unsigned int nanos) |
Forces the Current Thread to wait until the thread exits. | |
virtual void | run () |
Default implementation of the run method - does nothing. | |
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. | |
void | setDaemon (bool value) |
Sets if the given Thread is a Daemon Thread or not. | |
bool | isDaemon () const |
Returns whether this thread is a daemon thread or not, if true this thread cannot be joined. | |
const 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. | |
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, unsigned 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 long long | getId () |
Obtains the Thread Id of the current thread. | |
static Thread * | currentThread () |
Returns a pointer to the currently executing thread object. | |
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::util::concurrent::locks::LockSupport |
class | decaf::lang::Runtime |
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. A Thread can also be made a daemon, which makes it run in the background. The latter also affects VM termination behavior: the VM does not terminate automatically as long as there are non-daemon threads running.
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 | ) |
Constructs a new Thread with the given target Runnable task.
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.
task | the Runnable that this thread manages, if the task is NULL the Thread's run method is used instead. |
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. |
decaf::lang::Thread::Thread | ( | Runnable * | task, |
const std::string & | name | ||
) |
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.
virtual decaf::lang::Thread::~Thread | ( | ) | [virtual] |
static Thread* decaf::lang::Thread::currentThread | ( | ) | [static] |
static long long decaf::lang::Thread::getId | ( | ) | [static] |
std::string decaf::lang::Thread::getName | ( | ) | const |
Returns the Thread's assigned name.
int decaf::lang::Thread::getPriority | ( | ) | const |
Gets the currently set priority for this Thread.
Thread::State decaf::lang::Thread::getState | ( | ) | const |
Returns the currently set State of this Thread.
const UncaughtExceptionHandler* decaf::lang::Thread::getUncaughtExceptionHandler | ( | ) | const |
Set the handler invoked when this thread abruptly terminates due to an uncaught exception.
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::isDaemon | ( | ) | const |
Returns whether this thread is a daemon thread or not, if true this thread cannot be joined.
virtual void decaf::lang::Thread::join | ( | long long | millisecs, |
unsigned int | nanos | ||
) | [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 void decaf::lang::Thread::join | ( | ) | [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 void decaf::lang::Thread::join | ( | long long | millisecs | ) | [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 void decaf::lang::Thread::run | ( | ) | [virtual] |
Default implementation of the run method - does nothing.
Implements decaf::lang::Runnable.
Reimplemented in activemq::transport::mock::InternalCommandListener.
void decaf::lang::Thread::setDaemon | ( | bool | value | ) |
Sets if the given Thread is a Daemon Thread or not.
Daemon threads cannot be joined and its resource are automatically reclaimed when it terminates.
value | Boolean indicating if this thread should be a daemon thread or not. |
IllegalThreadStateException | if the thread is already active. |
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 rane 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 void decaf::lang::Thread::sleep | ( | long long | millisecs | ) | [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 void decaf::lang::Thread::sleep | ( | long long | millisecs, |
unsigned int | nanos | ||
) | [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 void decaf::lang::Thread::start | ( | ) | [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 void decaf::lang::Thread::yield | ( | ) | [static] |
Causes the currently executing thread object to temporarily pause and allow other threads to execute.
friend class decaf::lang::Runtime [friend] |
friend class decaf::util::concurrent::locks::LockSupport [friend] |
const int decaf::lang::Thread::MAX_PRIORITY = 10 [static] |
The maximum priority that a thread can have.
const int decaf::lang::Thread::MIN_PRIORITY = 1 [static] |
The minimum priority that a thread can have.
const int decaf::lang::Thread::NORM_PRIORITY = 5 [static] |
The default priority that a thread is given at create time.