Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp



Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

anonymous sychronization  RSS feed

 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a simple question for you.. I'm learning threads so maybe you can help me out...
if I have this code
class MyClass
{
void doit()
{
int x = 50;
int y = 100;
synchronized(stuff)
{
int z = 101;
int a = 32;
}
}
}
Explain what 'stuff' is please.
Thanks
-Dale
------------------
What's this H2SO4 doing in my fridge?? ( thud )
 
Fred Abbot
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you are writing the code i cannot tell you what stuff is but it better be an object as thats all you can synchronize on
 
Paul Michael
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Fred. But if that is the entirety of your code already then, the only thing you can use in place of "stuff" is the keyword "this" which refers to the particular Object instance you're currently using.
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!