• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in a Threads

 
Sekhar Choudary
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , code is here

I think methods increment() and reset() should be synchronized for thread safety.
Am i right.

Thanks
 
Milan Sutaria
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the variable Count is private. I am assuming a scenario where a single object of the class ThreadsEX4 is created & its reference is passed on to two threads, so that each thread can acces the varible & modify it.
In this i would suggest even the getCount method to be synchronized. Though i am not sure.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Similar Threads