multithreading - I Got different output of same java multi threading program in Eclipse and Netbeans ? -
multithreading - I Got different output of same java multi threading program in Eclipse and Netbeans ? -
i got different output of multi threading code in eclipse , netbeans ide, don't know how's come, , logic behind this.
and every time when execute code, show different output , plz help me.
public class mythread2 extends thread {
public void run()
{
`system.out.println("r1");` `` seek `` { thread.sleep(500); } catch(exception e) { } system.out.println("r2"); } public static void main(string args[]) { mythread2 t1=new mythread2(); mythread2 t2=new mythread2(); t1.start(); t2.start(); system.out.println(t1.isalive()); system.out.println(t2.isalive()); } }
output in eclipse: r1 r1 true true r2 r2
and output in netbeans : r1 true true r1 r2 r2
thread sceduled jvm
. jvm
selects run runnable thread highest priority. whenever new java thread created has same priority thread created it. so,in case both threads have same priority! hence,jvm using own algorithm(round robin scheduling) pick thread , select , execute them in order. doesn't have fixed order , totally unpredictable rate execution!
it'll give different output different sample runs on same ide,i.e., either netbeans
or eclipse
. can seek running both! may out of order previous run these scheduled jvm.
java multithreading netbeans
Comments
Post a Comment