Oracle® Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.2.1.1.0)

E69640-01

Thread Class Reference

#include <coherence/lang/Thread.hpp>

Inherits Object, and Runnable.

List of all members.


Detailed Description

An Object representing a thread of execution.

Author:
mf 2007.12.10

Public Types

typedef spec::Handle Handle
 Thread Handle definition.
typedef spec::View View
 Thread View definition.
typedef spec::Holder Holder
 Thread Holder definition.

Public Member Functions

virtual void run ()
 Invoke the Runnable.
virtual int64_t getId () const
 Return the Thread's unique ID.
virtual State getState () const
 Return the Thread's current state.
virtual String::View getName () const
 Return the Thread's name.
virtual
ThreadGroup::Handle 
getThreadGroup ()
 Return this thread's group, or NULL if the thread has terminated.
virtual ThreadGroup::View getThreadGroup () const
 Return this thread's group, or NULL if the thread has terminated.
virtual bool isAlive () const
 Tests if this thread is alive.
virtual void start ()
 Begin executing the Thread's runnable on a new system thread.
virtual void interrupt ()
 Request that the Thread stop executing.
virtual bool isInterrupted () const
 Return true iff the thread is interrupted.
virtual void join () const
 Wait for the Thread to reach the state_terminated state.
virtual void join (int64_t cMillis) const
 Wait for the Thread to reach the state_terminated state.
virtual void setName (String::View vsName)
 Set the Thread's name.
virtual TypedHandle
< const String
toString () const
 Output a human-readable description of this Object to the given stream.

Note that when overriding this method the return type must be TypedHandle<const String> rather then String::View. These two types are assignment compatible but not equivalent and declaring the override with String::View will not be a compatible override.

coherence::lang::operator<<(std::ostream, Object::View) is defined and will call into the toString method, to output Objects. If a managed String object is desired, the COH_TO_STRING macro can be used to build up a String from streamable contents and is generally how toString() will be implemented.

 Object::View vKey   = ...
 Object::View vValue = ...
 std::cout << vKey << " = " << vValue << std::endl;

 String::View vs = COH_TO_STRING(vKey << " = " << vValue);

The COH_TO_STRING macro is also the most common way to implement the toString method. For example:

 virtual TypedHandle<const String> Person::toString() const
     {
     return COH_TO_STRING("Name: " << f_sName << " SSN: " << f_nSSN);
     }

Returns:
a string representation of this object


Static Public Member Functions

static Thread::Handle currentThread ()
 Return the Thread on which the caller is executing.
static
ObjectArray::Handle 
getStackTrace (size32_t cTrim=0)
 Return a stack trace for this thread.
static String::View formatStackTrace (ObjectArray::View vaStack)
 Format a stack trace.
static String::View formatStacks (int64_t cMillisTimeout=-1)
 Return the stack trace of all known threads as a String.
static bool interrupted ()
 Return true iff the caller's thread has been interrupted, or timed out.
static void sleep (int64_t cMillis)
 Pause the current thread for the specified duration.
static void yield ()
 Temporarily pause the current thread.
static int64_t remainingTimeoutMillis ()
 Return the number of milliseconds before the calling thread will timeout.
static bool isTimedOut ()
 Return true if the calling thread is timed out.

Protected Types

enum  Maintenance
 Defines various thread maintenance tasks.

Protected Member Functions

virtual void onExit ()
 Called automatically on the thread prior to termination.
virtual void scheduleMaintenance (Maintenance nMaintenance) const
 Instruct the thread to perform maintenance.

Static Protected Member Functions

static void doGlobalMaintenance (Maintenance nMaintenance)
 Instruct all threads to perform maintenance.

Protected Attributes

MemberHandle
< ThreadGroup
m_hGroup
 The thread's group.
MemberHandle< Runnablem_hRunnable
 The inner runnable associated with this Thread.
MemberView< Stringm_vsName
 The thread's name.
FinalView< Stringf_vsDescription
 The thread's description.
size32_t m_cBytesStack
 The configured stack size;.
Volatile< int32_t > m_nState
 The current thread state.
int m_nMaintenanceMask
 Bit mask identifying required maintenance tasks.
int64_t m_lTimeout
 The thread's timeout value.

Member Function Documentation

virtual int64_t getId (  )  const [virtual]

Return the Thread's unique ID.

No two live thread's will have the same ID and no thread will have an id of 0.

Returns:
the Thread's unique ID.

virtual State getState (  )  const [virtual]

Return the Thread's current state.

Returns:
the Thread's current state

virtual String::View getName (  )  const [virtual]

Return the Thread's name.

Returns:
the Thread's name

virtual ThreadGroup::Handle getThreadGroup (  )  [virtual]

Return this thread's group, or NULL if the thread has terminated.

Returns:
this thread's group

virtual ThreadGroup::View getThreadGroup (  )  const [virtual]

Return this thread's group, or NULL if the thread has terminated.

Returns:
this thread's group

virtual bool isAlive (  )  const [virtual]

Tests if this thread is alive.

A thread is alive if it has been started and has not yet died.

Returns:
true if this thread is alive; false otherwise.

virtual void start (  )  [virtual]

Begin executing the Thread's runnable on a new system thread.

This method may only be called once per Thread instance.

Exceptions:
IllegalStateException if a called on a Thread which is not in the state state_initial.

virtual bool isInterrupted (  )  const [virtual]

Return true iff the thread is interrupted.

Note, Unlike Thread::interrupted() this does not check if the thread has timed-out.

Returns:
true iff the thread is interrupted

virtual void join ( int64_t  cMillis  )  const [virtual]

Wait for the Thread to reach the state_terminated state.

Parameters:
cMillis the maximum duration to wait, or zero for infinite

virtual void setName ( String::View  vsName  )  [virtual]

Set the Thread's name.

Parameters:
vsName the Thread's name

virtual void onExit (  )  [protected, virtual]

Called automatically on the thread prior to termination.

Any class extending this Thread and overriding this method much call this implementation to ensure that join() operations complete.

static Thread::Handle currentThread (  )  [static]

Return the Thread on which the caller is executing.

Returns:
the caller's thread

static ObjectArray::Handle getStackTrace ( size32_t  cTrim = 0  )  [static]

Return a stack trace for this thread.

Parameters:
cTrim the number of frames to trim from the top of the stack
Returns:
an array of StackTraceElements describing as much of the thread's stack as can be determined

static String::View formatStackTrace ( ObjectArray::View  vaStack  )  [static]

Format a stack trace.

Parameters:
vaStack the array of StackTraceElements to output, or NULL for the stack of the current thread

static String::View formatStacks ( int64_t  cMillisTimeout = -1  )  [static]

Return the stack trace of all known threads as a String.

This is a blocking operation, while the calling thread waits for all known threads to report their stack.

Parameters:
cMillisTimeout the maximum amount of time to wait for all threads to report their stacks, or -1 for the system default of twice the interrupt resolution
Returns:
the stack traces

static bool interrupted (  )  [static]

Return true iff the caller's thread has been interrupted, or timed out.

The thread's interrupt state is reset as part of this operation.

Returns:
true iff the caller's thread has been interrupted

static void sleep ( int64_t  cMillis  )  [static]

Pause the current thread for the specified duration.

Parameters:
cMillis the duration to pause the thread for.
Exceptions:
InterruptedException if the thread is interrupted while sleeping.

static int64_t remainingTimeoutMillis (  )  [static]

Return the number of milliseconds before the calling thread will timeout.

Note if the current thread is timed out then invoking this method will also interrupt the thread.

Returns:
the number of remaining milliseconds, 0 if timed out, or Integer64::max_value if disabled.

static bool isTimedOut (  )  [static]

Return true if the calling thread is timed out.

Note if the current thread is timed out then invoking this method will also interrupt the thread.

Returns:
true if the calling thread is timed out

virtual TypedHandle<const String> toString (  )  const [virtual]

Output a human-readable description of this Object to the given stream.

Note that when overriding this method the return type must be TypedHandle<const String> rather then String::View. These two types are assignment compatible but not equivalent and declaring the override with String::View will not be a compatible override.

coherence::lang::operator<<(std::ostream, Object::View) is defined and will call into the toString method, to output Objects. If a managed String object is desired, the COH_TO_STRING macro can be used to build up a String from streamable contents and is generally how toString() will be implemented.

 Object::View vKey   = ...
 Object::View vValue = ...
 std::cout << vKey << " = " << vValue << std::endl;

 String::View vs = COH_TO_STRING(vKey << " = " << vValue);

The COH_TO_STRING macro is also the most common way to implement the toString method. For example:

 virtual TypedHandle<const String> Person::toString() const
     {
     return COH_TO_STRING("Name: " << f_sName << " SSN: " << f_nSSN);
     }

Returns:
a string representation of this object

If the associated Runnable implements the coherence::util::Describable interface that content will be included as well.

Reimplemented from Object.


Member Data Documentation

int64_t m_lTimeout [protected]

The thread's timeout value.

Value which are greater or equal to zero are used to indicate timeout timestamps. Negative values are relative timeouts which haven't yet been realized into a timestamp. This allows for an optimization where we can avoid obtaining the current time when "setting" the timeout, and defer it until we are about to block.


The documentation for this class was generated from the following file:
Copyright © 2000, 2016, Oracle and/or its affiliates. All rights reserved.