"Java Concurrency Programming Combat" (vi)----Cancel and close

Source: Internet
Author: User

It is easy to start tasks and threads. However, sometimes we want to end a task or thread prematurely, perhaps because the user canceled the operation, or the application needs to be shut down quickly.

It's not easy to get tasks and threads to stop safely/quickly/reliably. Java does not provide any mechanism to safely terminate a thread, but it provides interrupts, a collaborative mechanism that enables one thread to terminate the work of another thread.

1, Mission canceled

If the external code can place it in the "done" state before an operation is completed properly, the operation can be called a cancellation. The reasons for canceling an operation are:

  • User request Cancellation
  • Operations with a time limit
  • Application events, such as dividing the search task into multiple threads, as long as one is found, the other threads do not need to continue.
  • Error
  • Shut down

"Java Concurrency Programming Combat" (vi)----Cancel and close

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.