activemq-cpp-3.4.0

decaf::lang::Thread Class Reference

A Thread is a concurrent unit of execution. More...

#include <src/main/decaf/lang/Thread.h>

Inheritance diagram for decaf::lang::Thread:

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 UncaughtExceptionHandlergetUncaughtExceptionHandler () 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 ThreadcurrentThread ()
 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

Detailed Description

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.

See also:
decaf.lang.ThreadGroup
Since:
1.0

Member Enumeration Documentation

Represents the various states that the Thread can be in during its lifetime.

Enumerator:
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.


Constructor & Destructor Documentation

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.

Parameters:
taskthe 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.

Parameters:
namethe 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.

Parameters:
taskthe Runnable that this thread manages, if the task is NULL the Thread's run method is used instead.
namethe name to assign to this Thread.
virtual decaf::lang::Thread::~Thread ( ) [virtual]

Member Function Documentation

static Thread* decaf::lang::Thread::currentThread ( ) [static]

Returns a pointer to the currently executing thread object.

Returns:
Pointer to the Thread object representing the currently running Thread.
static long long decaf::lang::Thread::getId ( ) [static]

Obtains the Thread Id of the current thread.

Returns:
Thread Id
std::string decaf::lang::Thread::getName ( ) const

Returns the Thread's assigned name.

Returns:
the Name of the Thread.
int decaf::lang::Thread::getPriority ( ) const

Gets the currently set priority for this Thread.

Returns:
an int value representing the Thread's current priority.
Thread::State decaf::lang::Thread::getState ( ) const

Returns the currently set State of this Thread.

Returns:
the Thread's current state.
const UncaughtExceptionHandler* decaf::lang::Thread::getUncaughtExceptionHandler ( ) const

Set the handler invoked when this thread abruptly terminates due to an uncaught exception.

Returns:
a pointer to the set UncaughtExceptionHandler.
bool decaf::lang::Thread::isAlive ( ) const

Returns true if the Thread is alive, meaning it has been started and has not yet died.

Returns:
true if the thread is alive.
bool decaf::lang::Thread::isDaemon ( ) const

Returns whether this thread is a daemon thread or not, if true this thread cannot be joined.

Returns:
true if the thread is a daemon thread.
virtual void decaf::lang::Thread::join ( long long  millisecs,
unsigned int  nanos 
) [virtual]

Forces the Current Thread to wait until the thread exits.

Parameters:
millisecsthe time in Milliseconds before the thread resumes
nanos0-999999 extra nanoseconds to sleep.
Exceptions:
IllegalArgumentExceptionif the nanoseconds parameter is out of range or the milliseconds paramter is negative.
InterruptedExceptionif 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.

Exceptions:
InterruptedExceptionif 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.

Parameters:
millisecsthe time in Milliseconds before the thread resumes
Exceptions:
IllegalArgumentExceptionif the milliseconds parameter is negative.
InterruptedExceptionif 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.

Parameters:
valueBoolean indicating if this thread should be a daemon thread or not.
Exceptions:
IllegalThreadStateExceptionif the thread is already active.
void decaf::lang::Thread::setName ( const std::string &  name)

Sets the name of the Thread to the new Name given by the argument name

name the new name of the Thread.

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.

Parameters:
valuethe new priority value to assign to this Thread.
Exceptions:
IllegalArgumentExceptionif 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.

Parameters:
handlerthe 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.

Parameters:
millisecstime in milliseconds to halt execution.
Exceptions:
IllegalArgumentExceptionif the milliseconds parameter is negative.
InterruptedExceptionif 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.

Parameters:
millisecstime in milliseconds to halt execution.
nanos0-999999 extra nanoseconds to sleep.
Exceptions:
IllegalArgumentExceptionif the nanoseconds parameter is out of range or the milliseconds paramter is negative.
InterruptedExceptionif 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.

Exceptions:
IllegalThreadStateExceptionif the thread has already been started.
RuntimeExceptionif the Thread cannot be created for some reason.
std::string decaf::lang::Thread::toString ( ) const

Returns a string that describes the Thread.

Returns:
string describing the Thread.
static void decaf::lang::Thread::yield ( ) [static]

Causes the currently executing thread object to temporarily pause and allow other threads to execute.


Friends And Related Function Documentation

friend class decaf::lang::Runtime [friend]

Field Documentation

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.


The documentation for this class was generated from the following file: