The study of Interruptedexception

Source: Internet
Author: User

First, put a overstack on the answer:

Understand:

(1) throws Interruptedexception is part of your method declaration and the return value of the method you call.

(2) When your method calls another method and throws a Interruptexception exception, you should think: is interruptexception a meaningful result for your method? If it is, Then your method can make an exception declaration and propagate the exception up. For example: Your method needs to wait for the network to pass over the numeric parameters to complete the calculation and return the results, if the network has been blocked so that the calculation process cannot be completed, you can spread the interruptedexception exception upward. If not, then you cannot Interruptedexception is thrown, but it should be captured. There are two things you should memorize in your heart: 1. Other threads may block your thread, or if you want to gracefully cancel your operation, you should return as soon as possible. 2. Even if your method can return meaningful values when encountering interruptedexception, the fact that the thread is disturbed is also important. If you call the code of your method and want to know if your method is experiencing interference during execution, You should write down: Threaed.currentthread (). Interrupt ()

The study of Interruptedexception

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.