Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
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 Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in a Threads" Watch "Doubt in a Threads" New topic

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.

Milan Sutaria
Ranch Hand

Joined: Jul 10, 2008
Posts: 122
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%
I agree. Here's the link:
subject: Doubt in a Threads
Similar Threads