| Author |
why thread run at end even than place at start in java?
|
Tahir Mehmood
Greenhorn
Joined: Nov 04, 2011
Posts: 3
|
|
public static void main(String[] args){
try{
Threadcheck tc=new Threadcheck();
new Thread(tc).start();
System.out.println("mid");
tc.show();
System.out.println("get threadcheck="+tc.getP());
System.out.println("I at end="+Threadcheck.i);
Threadshow ts=new Threadshow();
ts.show2();
System.out.println("get threadshow="+ts.get());
}catch(Exception ex){
System.out.println(ex);
}
}//main
Thread will run at end although written frist
output
mid
i form show=10
p form show=30
get threadcheck=30
I at end=11
i form show2=11
get threadshow=88888888
step10
step11
step12
|
 |
Chris Janicki
Greenhorn
Joined: Aug 30, 2006
Posts: 21
|
|
1. You didn't provide enough info to definitively respond.
2. Threads are funny things. They are not guaranteed to immediately start just because you call start(). You should search for some tutorials on "concurrency" in java for techniques to schedule/coordinate threads in a deterministic manner.
|
 |
 |
|
|
subject: why thread run at end even than place at start in java?
|
|
|