In general, the Main method main () ends when the thread ends

Source: Internet
Author: User

Suspend () is a run-time state that enters a blocking state (note that the lock flag is not released). Resume () when restoring state. Stop () means release all.

There are deprecated flags on these methods, which indicate that this method is not recommended for use.

In general, the Main method main () ends when the thread ends, but there may be situations where the thread needs to be interrupted. For multithreading in general, each thread is a loop, and if you break the thread we must find a way to get it out.

If the Main method main () wants to end a thread in a block (such as sleep or wait)

Then we can call interrupt () on the thread object from other processes. Used for blocking (or lock pooling) throws an exception interrupted Exception.

This exception causes the thread to break and execute the code in the catch.

Multi-Threading Focus: Two ways to implement multithreading, Synchronized, and producer and consumer issues (Producerconsumer.java files).

1 Package tomtexts;2 3Import java.util.*;4     classCounter {5           inti =1; 6            PublicString toString () {7                 returninteger.tostring (i);8           }9         }Ten         classtomtexts_23 { One            Public Static voidMain (string[] args) { AHashtable HT =NewHashtable (); -                  for(inti =0; I <10000; i++) { -                       //produce a number between 0 and: theInteger r =NewInteger (int) (Math.random () * -)); -                   if(Ht.containskey (R)) -((Counter) Ht.Get(r)). i++; -                   Else +Ht.put (R,NewCounter ()); -                 } +System. out. println (HT); A           } at}

In general, the Main method main () ends when the thread ends

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.