• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get variable

 
Juan Manuel Alberto de los Santos
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


thanks
[ August 07, 2008: Message edited by: Juan Manuel Alberto de los Santos ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't, not as the code is written. If "number" were an instance variable instead of a local variable, then it would be accessible:


There's potentially another problem: the variable "number" is being accessed by two different threads, and that can lead to problems with the two threads not seeing the same value for the variable. I believe that in this case, it's OK because of the call to join() and the synchronization that it involves. Anyone disagree?
 
Juan Manuel Alberto de los Santos
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your solution works perfectly for what i wanted !

the join() method is the key here, otherwise, i got a 0 (because it reads the variable before the run() completes)

thanks !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic