Share via


Thread Constructors

Definition

Overloads

Thread()

Allocates a new Thread object.

Thread(ThreadGroup, IRunnable, String, Int64, Boolean)

Allocates a new Thread object so that it has target as its run object, has the specified name as its name, belongs to the thread group referred to by group, has the specified stackSize, and inherits initial values for InheritableThreadLocal inheritable thread-local variables if inheritThreadLocals is true.

Thread(ThreadGroup, IRunnable, String, Int64)

Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group, and has the specified stack size.

Thread(ThreadGroup, Action, String)
Thread(ThreadGroup, IRunnable, String)

Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group.

Thread(IntPtr, JniHandleOwnership)

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

Thread(Action, String)
Thread(ThreadGroup, Action, String, Int64)
Thread(ThreadGroup, Action)
Thread(ThreadGroup, IRunnable)

Allocates a new Thread object.

Thread(IRunnable, String)

Allocates a new Thread object.

Thread(String)

Allocates a new Thread object.

Thread(Action)
Thread(ThreadGroup, String)

Allocates a new Thread object.

Thread(IRunnable)

Allocates a new Thread object.

Thread()

Allocates a new Thread object.

[Android.Runtime.Register(".ctor", "()V", "")]
public Thread ();
Attributes

Remarks

Allocates a new Thread object. This constructor has the same effect as #Thread(ThreadGroup,Runnable,String) Thread(null, null, gname), where gname is a newly generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer.

Java documentation for java.lang.Thread.Thread().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

Applies to

Thread(ThreadGroup, IRunnable, String, Int64, Boolean)

Allocates a new Thread object so that it has target as its run object, has the specified name as its name, belongs to the thread group referred to by group, has the specified stackSize, and inherits initial values for InheritableThreadLocal inheritable thread-local variables if inheritThreadLocals is true.

[Android.Runtime.Register(".ctor", "(Ljava/lang/ThreadGroup;Ljava/lang/Runnable;Ljava/lang/String;JZ)V", "", ApiSince=33)]
public Thread (Java.Lang.ThreadGroup? group, Java.Lang.IRunnable? target, string name, long stackSize, bool inheritThreadLocals);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/ThreadGroup;Ljava/lang/Runnable;Ljava/lang/String;JZ)V", "", ApiSince=33)>]
new Java.Lang.Thread : Java.Lang.ThreadGroup * Java.Lang.IRunnable * string * int64 * bool -> Java.Lang.Thread

Parameters

group
ThreadGroup

the thread group. If null and there is a security manager, the group is determined by SecurityManager#getThreadGroup SecurityManager.getThreadGroup(). If there is not a security manager or SecurityManager.getThreadGroup() returns null, the group is set to the current thread's thread group.

target
IRunnable

the object whose run method is invoked when this thread is started. If null, this thread's run method is invoked.

name
String

the name of the new thread

stackSize
Int64

the desired stack size for the new thread, or zero to indicate that this parameter is to be ignored

inheritThreadLocals
Boolean

if true, inherit initial values for inheritable thread-locals from the constructing thread, otherwise no initial values are inherited

Attributes

Remarks

Allocates a new Thread object so that it has target as its run object, has the specified name as its name, belongs to the thread group referred to by group, has the specified stackSize, and inherits initial values for InheritableThreadLocal inheritable thread-local variables if inheritThreadLocals is true.

This constructor is identical to #Thread(ThreadGroup,Runnable,String,long) with the added ability to suppress, or not, the inheriting of initial values for inheritable thread-local variables from the constructing thread. This allows for finer grain control over inheritable thread-locals. Care must be taken when passing a value of false for inheritThreadLocals, as it may lead to unexpected behavior if the new thread executes code that expects a specific thread-local value to be inherited.

Specifying a value of true for the inheritThreadLocals parameter will cause this constructor to behave exactly like the Thread(ThreadGroup, Runnable, String, long) constructor.

Added in 9.

Java documentation for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String, long, boolean).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Thread(ThreadGroup, IRunnable, String, Int64)

Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group, and has the specified stack size.

[Android.Runtime.Register(".ctor", "(Ljava/lang/ThreadGroup;Ljava/lang/Runnable;Ljava/lang/String;J)V", "")]
public Thread (Java.Lang.ThreadGroup? group, Java.Lang.IRunnable? target, string name, long stackSize);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/ThreadGroup;Ljava/lang/Runnable;Ljava/lang/String;J)V", "")>]
new Java.Lang.Thread : Java.Lang.ThreadGroup * Java.Lang.IRunnable * string * int64 -> Java.Lang.Thread

Parameters

group
ThreadGroup

the thread group. If null and there is a security manager, the group is determined by SecurityManager#getThreadGroup SecurityManager.getThreadGroup(). If there is not a security manager or SecurityManager.getThreadGroup() returns null, the group is set to the current thread's thread group.

target
IRunnable

the object whose run method is invoked when this thread is started. If null, this thread's run method is invoked.

name
String

the name of the new thread

stackSize
Int64

the desired stack size for the new thread, or zero to indicate that this parameter is to be ignored.

Attributes

Exceptions

if group.destroy() has already been done

Remarks

Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group, and has the specified stack size.

This constructor is identical to #Thread(ThreadGroup,Runnable,String) with the exception of the fact that it allows the thread stack size to be specified. The stack size is the approximate number of bytes of address space that the virtual machine is to allocate for this thread's stack. <b>The effect of the stackSize parameter, if any, is highly platform dependent.</b>

On some platforms, specifying a higher value for the stackSize parameter may allow a thread to achieve greater recursion depth before throwing a StackOverflowError. Similarly, specifying a lower value may allow a greater number of threads to exist concurrently without throwing an OutOfMemoryError (or other internal error). The details of the relationship between the value of the stackSize parameter and the maximum recursion depth and concurrency level are platform-dependent. <b>On some platforms, the value of the stackSize parameter may have no effect whatsoever.</b>

The virtual machine is free to treat the stackSize parameter as a suggestion. If the specified value is unreasonably low for the platform, the virtual machine may instead use some platform-specific minimum value; if the specified value is unreasonably high, the virtual machine may instead use some platform-specific maximum. Likewise, the virtual machine is free to round the specified value up or down as it sees fit (or to ignore it completely).

Specifying a value of zero for the stackSize parameter will cause this constructor to behave exactly like the Thread(ThreadGroup, Runnable, String) constructor.

Due to the platform-dependent nature of the behavior of this constructor, extreme care should be exercised in its use. The thread stack size necessary to perform a given computation will likely vary from one JRE implementation to another. In light of this variation, careful tuning of the stack size parameter may be required, and the tuning may need to be repeated for each JRE implementation on which an application is to run.

Implementation note: Java platform implementers are encouraged to document their implementation's behavior with respect to the stackSize parameter.

Added in 1.4.

Java documentation for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String, long).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

Applies to

Thread(ThreadGroup, Action, String)

public Thread (Java.Lang.ThreadGroup group, Action runHandler, string threadName);
new Java.Lang.Thread : Java.Lang.ThreadGroup * Action * string -> Java.Lang.Thread

Parameters

group
ThreadGroup
runHandler
Action
threadName
String

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Thread(ThreadGroup, IRunnable, String)

Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group.

[Android.Runtime.Register(".ctor", "(Ljava/lang/ThreadGroup;Ljava/lang/Runnable;Ljava/lang/String;)V", "")]
public Thread (Java.Lang.ThreadGroup? group, Java.Lang.IRunnable? target, string name);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/ThreadGroup;Ljava/lang/Runnable;Ljava/lang/String;)V", "")>]
new Java.Lang.Thread : Java.Lang.ThreadGroup * Java.Lang.IRunnable * string -> Java.Lang.Thread

Parameters

group
ThreadGroup

the thread group. If null and there is a security manager, the group is determined by SecurityManager#getThreadGroup SecurityManager.getThreadGroup(). If there is not a security manager or SecurityManager.getThreadGroup() returns null, the group is set to the current thread's thread group.

target
IRunnable

the object whose run method is invoked when this thread is started. If null, this thread's run method is invoked.

name
String

the name of the new thread

Attributes

Exceptions

if group.destroy() has already been done

Remarks

Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group.

If there is a security manager, its SecurityManager#checkAccess(ThreadGroup) checkAccess method is invoked with the ThreadGroup as its argument.

In addition, its checkPermission method is invoked with the RuntimePermission("enableContextClassLoaderOverride") permission when invoked directly or indirectly by the constructor of a subclass which overrides the getContextClassLoader or setContextClassLoader methods.

The priority of the newly created thread is set equal to the priority of the thread creating it, that is, the currently running thread. The method #setPriority setPriority may be used to change the priority to a new value.

The newly created thread is initially marked as being a daemon thread if and only if the thread creating it is currently marked as a daemon thread. The method #setDaemon setDaemon may be used to change whether or not a thread is a daemon.

Java documentation for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

Applies to

Thread(IntPtr, JniHandleOwnership)

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

protected Thread (IntPtr javaReference, Android.Runtime.JniHandleOwnership transfer);
new Java.Lang.Thread : nativeint * Android.Runtime.JniHandleOwnership -> Java.Lang.Thread

Parameters

javaReference
IntPtr

nativeint

A IntPtrcontaining a Java Native Interface (JNI) object reference.

transfer
JniHandleOwnership

A JniHandleOwnershipindicating how to handle javaReference

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Thread(Action, String)

public Thread (Action runHandler, string threadName);
new Java.Lang.Thread : Action * string -> Java.Lang.Thread

Parameters

runHandler
Action
threadName
String

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Thread(ThreadGroup, Action, String, Int64)

public Thread (Java.Lang.ThreadGroup group, Action runHandler, string threadName, long stackSize);
new Java.Lang.Thread : Java.Lang.ThreadGroup * Action * string * int64 -> Java.Lang.Thread

Parameters

group
ThreadGroup
runHandler
Action
threadName
String
stackSize
Int64

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Thread(ThreadGroup, Action)

public Thread (Java.Lang.ThreadGroup group, Action runHandler);
new Java.Lang.Thread : Java.Lang.ThreadGroup * Action -> Java.Lang.Thread

Parameters

group
ThreadGroup
runHandler
Action

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Thread(ThreadGroup, IRunnable)

Allocates a new Thread object.

[Android.Runtime.Register(".ctor", "(Ljava/lang/ThreadGroup;Ljava/lang/Runnable;)V", "")]
public Thread (Java.Lang.ThreadGroup? group, Java.Lang.IRunnable? target);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/ThreadGroup;Ljava/lang/Runnable;)V", "")>]
new Java.Lang.Thread : Java.Lang.ThreadGroup * Java.Lang.IRunnable -> Java.Lang.Thread

Parameters

group
ThreadGroup

the thread group. If null and there is a security manager, the group is determined by SecurityManager#getThreadGroup SecurityManager.getThreadGroup(). If there is not a security manager or SecurityManager.getThreadGroup() returns null, the group is set to the current thread's thread group.

target
IRunnable

the object whose run method is invoked when this thread is started. If null, this thread's run method is invoked.

Attributes

Exceptions

if group.destroy() has already been done

Remarks

Allocates a new Thread object. This constructor has the same effect as #Thread(ThreadGroup,Runnable,String) Thread(group, target, gname) ,where gname is a newly generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer.

Java documentation for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

Applies to

Thread(IRunnable, String)

Allocates a new Thread object.

[Android.Runtime.Register(".ctor", "(Ljava/lang/Runnable;Ljava/lang/String;)V", "")]
public Thread (Java.Lang.IRunnable? target, string name);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/Runnable;Ljava/lang/String;)V", "")>]
new Java.Lang.Thread : Java.Lang.IRunnable * string -> Java.Lang.Thread

Parameters

target
IRunnable

the object whose run method is invoked when this thread is started. If null, this thread's run method is invoked.

name
String

the name of the new thread

Attributes

Remarks

Allocates a new Thread object. This constructor has the same effect as #Thread(ThreadGroup,Runnable,String) Thread(null, target, name).

Java documentation for java.lang.Thread.Thread(java.lang.Runnable, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

Applies to

Thread(String)

Allocates a new Thread object.

[Android.Runtime.Register(".ctor", "(Ljava/lang/String;)V", "")]
public Thread (string name);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/String;)V", "")>]
new Java.Lang.Thread : string -> Java.Lang.Thread

Parameters

name
String

the name of the new thread

Attributes

Remarks

Allocates a new Thread object. This constructor has the same effect as #Thread(ThreadGroup,Runnable,String) Thread(null, null, name).

Java documentation for java.lang.Thread.Thread(java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

Applies to

Thread(Action)

public Thread (Action runHandler);
new Java.Lang.Thread : Action -> Java.Lang.Thread

Parameters

runHandler
Action

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Thread(ThreadGroup, String)

Allocates a new Thread object.

[Android.Runtime.Register(".ctor", "(Ljava/lang/ThreadGroup;Ljava/lang/String;)V", "")]
public Thread (Java.Lang.ThreadGroup? group, string name);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/ThreadGroup;Ljava/lang/String;)V", "")>]
new Java.Lang.Thread : Java.Lang.ThreadGroup * string -> Java.Lang.Thread

Parameters

group
ThreadGroup

the thread group. If null and there is a security manager, the group is determined by SecurityManager#getThreadGroup SecurityManager.getThreadGroup(). If there is not a security manager or SecurityManager.getThreadGroup() returns null, the group is set to the current thread's thread group.

name
String

the name of the new thread

Attributes

Exceptions

if group.destroy() has already been done

Remarks

Allocates a new Thread object. This constructor has the same effect as #Thread(ThreadGroup,Runnable,String) Thread(group, null, name).

Java documentation for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

Applies to

Thread(IRunnable)

Allocates a new Thread object.

[Android.Runtime.Register(".ctor", "(Ljava/lang/Runnable;)V", "")]
public Thread (Java.Lang.IRunnable? target);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/Runnable;)V", "")>]
new Java.Lang.Thread : Java.Lang.IRunnable -> Java.Lang.Thread

Parameters

target
IRunnable

the object whose run method is invoked when this thread is started. If null, this classes run method does nothing.

Attributes

Remarks

Allocates a new Thread object. This constructor has the same effect as #Thread(ThreadGroup,Runnable,String) Thread(null, target, gname), where gname is a newly generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer.

Java documentation for java.lang.Thread.Thread(java.lang.Runnable).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

Applies to