Thread start Mode One (Thread.Start): Source analysis

Source: Internet
Author: User

Package Day11;class Testdemo extends thread{int count = 0;/*public void Add () {while (count<100) {count++; System.out.println (count);}} */public void Run () {while (count<100) {count++; System.out.println (count);}}} public class Threaddemo {public static void main (string[] args) {Testdemo td = New Testdemo (); Testdemo TD2 = new Testdemo ();//td.add ();/*td.start (); Td.start (); Java.lang.IllegalThreadStateException cause resolution: The same thread cannot call the Start method repeatedly, because the start method is called repeatedly, the status is not new, Then the threadstatus is not equal to 0.  Then the new Illegalthreadstateexception () exception is thrown, and this exception is thrown in the method, so whoever calls this method will throw an exception if the request is not met. Source code: Public synchronized void Start () {This method was not invoked for the main method thread or "system" group T Hreads Created/set up by the VM.   Any of the new functionality added to the "This method" in the future May has the to also is added to the VM.     A Zero status value corresponds to state "NEW".         This means that the Start method is not awakened by the system's main method thread or by a system community thread created by the virtual machine.    After any new features add this method, you have to add this functionality to both VMs.                 0 This state is equal to the ' New ' state. IF (threadstatus! = 0) throw new illegalthreadstateexception ();        Group.add (this);        Start0 ();  if (Stopbeforestart) {stop0 (throwablefromstop); }    } */}}

  

Thread start Mode One (Thread.Start): Source analysis

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.