java - Call start method two times -
java - Call start method two times -
why next code throws exception?
class mythread extends thread { public static void main (string [] args) { mythread t = new mythread(); t.start(); system.out.print("one. "); t.start(); system.out.print("two. "); } public void run() { system.out.print("thread "); } }
could point me out jls
?
that's contract of start() method :
public void start() causes thread begin execution; java virtual machine calls run method of thread. result 2 threads running concurrently: current thread (which returns phone call start method) , other thread (which executes run method). never legal start thread more once. in particular, thread may not restarted 1 time has completed execution. throws: illegalthreadstateexception - if thread started.
you can't start thread twice.
java multithreading
Comments
Post a Comment