Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why thread run at end even than place at start in java?

 
Tahir Mehmood
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
Mac OS X Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic