Some methods of Java threading Learning-thread

Source: Internet
Author: User

IsAlive tests whether the thread is active. The so-called activity State, refers to the thread has been started and has not been terminated.

Sleep means that execution is paused, but the thread is still alive, that is, isalive or true.

GetID gets the thread unique identity.


stopping a thread is more important than the beginning and end.

This explains, stop the thread, can not use stop, this method is deprecated, like suspend and resume, are obsolete methods, using them may produce unpredictable results.


The current methods of stopping threads are:

1. Using the exit flag, the thread terminates after the Run method completes. It is recommended to use the method of replanting.

2, use stop, not recommended, should not be used.

3, use interrupt. This method does not stop immediately, but is a similar flag in the thread.


To determine if a thread is in a stopped state:

1, Interrupted (), indicates whether the current thread is interrupted. If true, indicates an interrupt, it will break the flag 0 (that is, set to false)

2, isinterrupted (), indicates whether the thread is interrupted. Returns true to indicate an interrupt and does not empty the interrupt flag.

The difference between the two is that either object invocation, or x.interrupted (), indicates whether the thread that called the method statement was interrupted. The latter x.isinterrupted () indicates whether the X object has been interrupted.





This article is from the "Happy Cup of Tea" blog, please be sure to keep this source http://gugw9handsome.blog.51cto.com/1187812/1784161

Some methods of Java threading Learning-thread

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.