• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads

 
Rajeev Iyer
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..
Is a seperate set of variables created in the run method for each call to the thread or the same copy shared??
Rather, if i have a variable 'x' in the run method, if I craete more than one thread, each thread will occupy a seperate copy or the same variable will be shared??
regards
 
Rajesh Jumde
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya Rajeev, It will create a new variable for new thread.
It behaves same that of a method level attributes.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variables are created with the object, not the thread.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on the type of variable we're talking about. Instance variables are created with the object. Class variables are created with the class. Local variables are created every time a thread starts execution of a given method. It sounded to me like Rajeev was talking about local variables, but I'm not sure. If x is a local variable inside a run() method, then each time a new thread starts that method, it makes its own new copy of x.
[ September 26, 2002: Message edited by: Jim Yingst ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!