This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in a Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in a Threads" Watch "Doubt in a Threads" New topic
Author

Doubt in a Threads

Sekhar Choudary
Ranch Hand

Joined: May 03, 2008
Posts: 57
Hi , code is here

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

Thanks
Milan Sutaria
Ranch Hand

Joined: Jul 10, 2008
Posts: 118
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.


SCJP 6 83%
Working on SCWCD/OCPJWCD
 
Consider Paul's rocket mass heater.
 
subject: Doubt in a Threads
 
Similar Threads
synchronized