Android Guides | Samples

Java.Lang.Thread Class

A Thread is a concurrent unit of execution.

See Also: Thread

Syntax

[Android.Runtime.Register("java/lang/Thread", DoNotGenerateAcw=true)]
public class Thread : Object, IRunnable, IDisposable

Remarks

A Thread is a concurrent unit of execution. It has its own call stack for methods being invoked, their arguments and local variables. Each application has at least one thread running when it is started, the main thread, in the main ThreadGroup. The runtime keeps its own threads in the system thread group.

There are two ways to execute code in a new thread. You can either subclass Thread and overriding its Thread.Run method, or construct a new Thread and pass a IRunnable to the constructor. In either case, the Thread.Start method must be called to actually execute the new Thread.

Each Thread has an integer priority that affect how the thread is scheduled by the OS. A new thread inherits the priority of its parent. A thread's priority can be set using the Thread.Priority method.

[Android Documentation]

Requirements

Namespace: Java.Lang
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Java.Lang.Thread are listed below.

See Also: Object

Public Constructors

Constructs a new Thread with no Runnable object and a newly generated name.
Constructs a new Thread with a Runnable object and a newly generated name.
Constructs a new Thread with no Runnable object and the name provided.
Constructs a new Thread with a Runnable object and name provided.
Constructs a new Thread with a Runnable object and a newly generated name.
Constructs a new Thread with no Runnable object, the given name and belonging to the ThreadGroup passed as parameter.
Constructs a new Thread with a Runnable object, the given name and belonging to the ThreadGroup passed as parameter.
Constructs a new Thread with a Runnable object, the given name and belonging to the ThreadGroup passed as parameter.

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Fields

const
MaxPriorityInt32 (10). The maximum priority value allowed for a thread.
const
MinPriorityInt32 (1). The minimum priority value allowed for a thread.
const
NormPriorityInt32 (5). The normal (default) priority value assigned to the main thread.

Public Properties

[read-only]
static
AllStackTracesIDictionary<Thread, StackTraceElement[]>. Returns a map of all the currently live threads to their stack traces.
ContextClassLoaderClassLoader. Returns the context ClassLoader for this Thread.
DaemonBoolean. Tests whether this is a daemon thread.
static
DefaultUncaughtExceptionHandlerThread+IUncaughtExceptionHandler. Returns the default exception handler that's executed when uncaught exception terminates a thread.
[read-only]
IdInt64. Returns the thread's identifier.
[read-only]
IsAliveBoolean. Returns true if the receiver has already been started and still runs code (hasn't died yet).
[read-only]
IsInterruptedBoolean. Returns a boolean indicating whether the receiver has a pending interrupt request (true) or not ( false)
NameString. Returns the name of the Thread.
PriorityInt32. Returns the priority of the Thread.
[read-only]
ThreadGroupThreadGroup. Returns the ThreadGroup to which this Thread belongs.
UncaughtExceptionHandlerThread+IUncaughtExceptionHandler. Returns the thread's uncaught exception handler.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

static
ActiveCount() : Int32
Returns the number of active Threads in the running Thread's group and its subgroups.
CheckAccess()
Does nothing.
CountStackFrames() : Int32
Returns the number of stack frames in this thread.
static
CurrentThread() : Thread
Returns the Thread of the caller, that is, the current Thread.
Destroy()
Throws UnsupportedOperationException.
static
DumpStack()
Prints to the standard error stream a text representation of the current stack for this Thread.
static
Enumerate(Thread[]) : Int32
Copies an array with all Threads which are in the same ThreadGroup as the receiver - and subgroups - into the array threads passed as parameter.
GetStackTrace() : StackTraceElement[]
Returns an array of StackTraceElement representing the current thread's stack.
GetState() : Thread+State
Returns the current state of the Thread.
static
HoldsLock(Object) : Boolean
Indicates whether the current Thread has a monitor lock on the specified object.
Interrupt()
Posts an interrupt request to this Thread.
static
Interrupted() : Boolean
Returns a boolean indicating whether the current Thread ( currentThread()) has a pending interrupt request ( true) or not (false).
Join()
Blocks the current Thread (Thread.currentThread()) until the receiver finishes its execution and dies.
Join(Int64)
Blocks the current Thread (Thread.currentThread()) until the receiver finishes its execution and dies or the specified timeout expires, whatever happens first.
Join(Int64, Int32)
Blocks the current Thread (Thread.currentThread()) until the receiver finishes its execution and dies or the specified timeout expires, whatever happens first.
Resume()
Throws UnsupportedOperationException.
Run()
Calls the run() method of the Runnable object the receiver holds.
static
Sleep(Int64)
Causes the thread which sent this message to sleep for the given interval of time (given in milliseconds).
static
Sleep(Int64, Int32)
Causes the thread which sent this message to sleep for the given interval of time (given in milliseconds and nanoseconds).
Start()
Starts the new Thread of execution.
Stop()
Requests the receiver Thread to stop and throw ThreadDeath.
Stop(Throwable)
Throws UnsupportedOperationException.
Suspend()
Throws UnsupportedOperationException.
static
Yield()
Causes the calling Thread to yield execution time to another Thread that is ready to run.