Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt in a Threads  RSS feed

 
Sekhar Choudary
Ranch Hand
Posts: 57
  • 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
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!

Similar Threads