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