Concurrency Basics (ii): API Summary of the thread class _ Concurrency

Source: Internet
Author: User

The thread class is a class of threads in Java that is provided to users to create, manipulate, and obtain information about threads. Is the basis of all Java threads, mastering this class is very necessary, first look at its API. 1, field summary static int max_priority thread can have the highest priority static int min_priority thread can have the lowest priority static int norm_priority assigned to the default priority of the thread 2, constructed Method Summary thread (): Allocates a new thread object. Thread (Runnable target): Assigns a new Thread object. Thread (Runnable target, String name): Assigns a new Thread object. Thread (String name): Assigns a new Thread object. parameter is thread name threads (threadgroup Group, Runnable target): Allocates a new thread object. Thread (threadgroup group, Runnable Target, String name): Assigns a new Thread object so that target can be run as its object, the specified name as its name, and as referenced by the group A member of a thread group. Thread (threadgroup group, Runnable Target, String name, Long stacksize): Assigns a new Thread object so that target can be run as its object and the specified name as its name As a member of the thread group referenced by group and has the specified stack size. Thread (threadgroup Group, String name): Assigns a new Thread object.

Attention:
  Thread groups (Threadgroup) are obsolete and discarded, so there is no need to study thread groups, only to know that there is this existence. According to the Java programming idea, the thread group failed an unsuccessful attempt 3, method summary 3.1, static method CurrentThread (): Returns a reference to the currently executing thread object. static int Activecount (): Returns the number of active threads in the thread group of the current thread. Static Boolean Interrupted (): Tests if the thread has been interrupted. static void sleep (Long Millis): Allows the currently executing thread to hibernate (suspend execution) within a specified number of milliseconds, which is affected by the system timer and scheduler precision and accuracy. static void sleep (long millis, int Nanos): Allows the currently executing thread to hibernate (suspend execution) within the specified number of milliseconds plus the specified number of nanoseconds, which is affected by the system timer and scheduler precision and accuracy. static void Yield (): Pauses the currently executing thread object and executes other threads. Static Boolean holdslock (Object obj): Returns True if and only if the thread holds a monitor lock on the specified object. static void DumpStack (): Prints the current thread's stack trace to the standard error stream. static int Enumerate (thread[] tarray): Copies each active thread in the current thread's thread group and its subgroups into the specified array. Static map< thread,stacktraceelement[]> getallstacktraces (): Returns a mapping of the stack trace for all active threads. Static Thread.uncaughtexceptionhandler Getdefaultuncaughtexceptionhandler (): Returns the default handler that is invoked when a thread suddenly terminates because it has not caught an exception. The static void Setdefaultuncaughtexceptionhandler (Thread.uncaughtexceptionhandler eh) setting terminates abruptly when the thread has not caught an exception. And the default handler that is invoked when no other handler is defined for the thread. 3.2, get the information of the threadLong GetId (): Returns a unique identifier for this thread. String getName (): Returns the name of the thread. int getpriority (): Returns the priority level of a thread. Thread.state getState (): Returns the state of the thread. Threadgroup Getthreadgroup (): Returns the thread group to which this thread belongs. ClassLoader Getcontextclassloader (): Returns the context ClassLoader for this thread. Stacktraceelement[] Getstacktrace (): Returns an array of stack trace elements representing the thread stack dump. Thread.uncaughtexceptionhandler Getuncaughtexceptionhandler (): Returns the handler that was invoked when the thread suddenly terminated because it had not caught an exception. 3.3. Other operations of the thread void CheckAccess (): Determines whether the currently running thread has permission to modify the thread. void Interrupt (): Interrupt thread. Boolean isinterrupted (): Tests whether the thread has been interrupted. Boolean isAlive (): Tests whether the thread is active. Boolean Isdaemon (): Tests whether the thread is a daemon thread. That is, the background thread void SetName (String name): Changes the thread name to the same as the parameter name. void setpriority (int newpriority): Changes the priority of a thread. void Setdaemon (Boolean on): marks the thread as a daemon thread or user thread. Also called a background thread (a generic service thread in the background) void Setcontextclassloader (ClassLoader cl): Sets the context ClassLoader for the thread. void Setuncaughtexceptionhandler (Thread.uncaughtexceptionhandler eh): Sets the handler that is invoked when the thread suddenly terminates because it has not caught an exception. void join (): Waits for the thread to terminate. void join (Long Millis): The maximum time to wait for the thread to terminate is Millis milliseconds. void join (long millis, int nanos): Waiting for the thread to terminateThe maximum time is Millis milliseconds + Nanos nanosecond. void Start (): Causes the thread to start executing, and the Java virtual machine invokes the thread's Run method. String toString (): Returns the string representation of the thread, including the thread name, priority, and thread group.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.