Introduction to Thread class methods in "Go" Java

Source: Internet
Author: User
Tags stack trace terminates thread class

Text: Introduction to Thread class methods in Java

http://blog.csdn.net/seapeak007/article/details/53395609

This article to find time to analyze!!! : http://blog.csdn.net/apei830/article/details/4503112

---------------------------------------------------------------

Method Summary
static int Activecount ()
Returns the number of active threads in the thread group for the current thread.
void CheckAccess ()
Determines whether the currently running thread has permission to modify the thread.
int Countstackframes ()
is obsolete. The definition of the call depends on suspend (), but it has been objected to. In addition, the result of the call is never clear-reaching.
Static Thread CurrentThread ()
Returns a reference to the currently executing thread object.
void Destroy ()
is obsolete. The method was originally used to destroy the thread, but no cleanup was made. Any monitor it maintains will remain locked. However, this method is never implemented. Even if it is to be implemented, it is most likely to be deadlocked in suspend () mode. If the target thread is destroyed while maintaining a lock that protects critical system resources, no thread can access the resource again at any time. If another thread has attempted to lock the resource, a deadlock occurs. Such deadlocks often prove themselves to be "frozen" processes. For more information, see why disapprove of using Thread.stop, Thread.Suspend, and Thread.Resume?.
static void DumpStack ()
Prints the stack trace of the current thread 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 map of the stack traces for all active threads.
ClassLoader Getcontextclassloader ()
Returns the context ClassLoader for this thread.
Static Thread.uncaughtexceptionhandler Getdefaultuncaughtexceptionhandler ()
Returns the default handler that is called when the thread terminates abruptly because the exception was not caught.
Long GetId ()
Returns the identifier of the thread.
String GetName ()
Returns the name of the thread.
int getpriority ()
Returns the priority of the thread.
Stacktraceelement[] Getstacktrace ()
Returns an array of stack trace elements representing the stack dump of the thread.
Thread.state GetState ()
Returns the state of the thread.
Threadgroup Getthreadgroup ()
Returns the thread group to which the thread belongs.
Thread.uncaughtexceptionhandler Getuncaughtexceptionhandler ()
Returns the handler that is called when the thread terminates abruptly because the exception was not caught.
Static Boolean holdslock (Object obj)
Returns true if and only if the monitor lock is persisted on the specified object by the front thread.
void Interrupt ()
The thread is disconnected.
Static Boolean Interrupted ()
Test if the front thread has been interrupted.
Boolean isAlive ()
Tests whether the thread is active.
Boolean Isdaemon ()
Tests whether the thread is a daemon thread.
Boolean isinterrupted ()
Tests whether the thread has been interrupted.
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)
The maximum time to wait for the thread to terminate is Millis milliseconds + Nanos nanoseconds.
void Resume ()
is obsolete. This method is only used with suspend (), but suspend () has been objected to because it has a deadlock tendency. For more information, see why disapprove of using Thread.stop, Thread.Suspend, and Thread.Resume?.
void Run ()
If the thread is constructed using a standalone Runnable run object, the Run method of the Runnable object is called, otherwise the method does nothing and returns.
void Setcontextclassloader (ClassLoader cl)
Sets the context ClassLoader for this thread.
void Setdaemon (Boolean on)
Mark the thread as either a daemon thread or a user thread.
static void Setdefaultuncaughtexceptionhandler (Thread.uncaughtexceptionhandler eh)
Sets the default handler that is called when a thread is abruptly terminated because it did not catch an exception, and no other handlers are defined for the thread.
void SetName (String name)
Change the thread name so that it is the same as the parameter name.
void setpriority (int newpriority)
The priority of the thread to be rerouted.
void Setuncaughtexceptionhandler (Thread.uncaughtexceptionhandler eh)
Sets the handler that is called when the thread terminates abruptly because the exception was not caught.
static void sleep (long Millis)
Lets the currently executing thread hibernate (suspends execution) within the specified number of milliseconds, which is affected by the accuracy and accuracy of the system timer and scheduler.
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 accuracy and accuracy of the system timer and scheduler.
void Start ()
Causes the thread to start executing, and the Java virtual machine calls the thread's Run method.
void Stop ()
is obsolete. This method has inherent insecurity. Terminating a thread with Thread.stop frees all monitors it has locked (as a natural consequence of unchecked threaddeath exceptions that propagate up the stack). If any objects previously protected by these monitors are in an inconsistent state, the corrupted object will be visible to other threads, which may cause arbitrary behavior. Many uses of stop should be replaced by code that modifies only certain variables to indicate that the target thread should stop running. The target thread should check the variable periodically, and if the variable indicates that it is going to stop running, return from its run method. If the target thread waits for a long time (for example, based on a condition variable), you should use the interrupt method to interrupt the wait. For more information, see why disapprove of using Thread.stop, Thread.Suspend, and Thread.Resume?.
void Stop (Throwable obj)
is obsolete. This method has inherent insecurity. For more information, see Stop (). The additional danger of this method is that it can be used to generate exceptions that the target thread is not prepared to handle (including checked exceptions that the thread is less likely to throw if the method is not available). For more information, see why disapprove of using Thread.stop, Thread.Suspend, and Thread.Resume?.
void Suspend ()
is obsolete. The method has been objected to because of its inherent deadlock tendency. If the target thread is suspended and there is a lock on the monitor that secures the critical system resources, no thread can access the resource until the target thread restarts. If the thread that is restarting the target thread wants to lock the monitor before calling resume, a deadlock occurs. This type of deadlock usually proves itself to be a "frozen" process. For more information, see why disapprove of using Thread.stop, Thread.Suspend, and Thread.Resume?.
String toString ()
Returns the string representation of the thread, including the thread name, priority, and thread group.
static void Yield ()
Pauses the currently executing thread object and executes other threads.

Introduction to Thread class methods in "Go" Java

Related Article

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.