my dog learned polymorphism*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Should the criteriaFind be synchronized? 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 » Developer Certification (SCJD/OCMJD)
Bookmark "Should the criteriaFind be synchronized?" Watch "Should the criteriaFind be synchronized?" New topic
Author

Should the criteriaFind be synchronized?

Ray Cheeny
Ranch Hand

Joined: Aug 21, 2002
Posts: 74
Hi,
I implemented the criteriaFind in my RemoteAccess.
Should I make it synchronized?
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Ray,
That's according to how and where you implemented criteriaFind. In my case it was not necessay because each client had a separate object in which criteriaFind was implemented. If you implemented it in Data or a child and there is only one Data object that is shared by all the clients, then odds are you will need to synchronize it.
Hope this helps,
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
no more user
Ranch Hand

Joined: Aug 07, 2002
Posts: 39
hi,
Originally posted by Michel Morris: In my case it was not necessay because each client had a separate object in which criteriaFind was implemented. If you implemented it in Data or a child and there is only one Data object that is shared by all the clients, then odds are you will need to synchronize it.


There are more than one object that access db file at the same time or the search feature is apart of Data object!?
can you talk about!?
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Alex,

There are more than one object that access db file at the same time or the search feature is apart of Data object!?

The search feature is apart from the Data object in my design. I had a DataSearch interface which had the one method criteriaFind. That was implemented by CriteriaSearch. Each client had its own CriteriaSearch object, so there was no need to synchronize criteriaFind.
Michael Morris
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Sorry Ray, but I had to delete the other post you had that was the same question. Duplicate posts you know.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Kruger Scheitz
Ranch Hand

Joined: Jul 31, 2002
Posts: 72
quote:
--------------------------------------------------------------------------------
Originally posted by Michel Morris: In my case it was not necessay because each client had a separate object in which criteriaFind was implemented. If you implemented it in Data or a child and there is only one Data object that is shared by all the clients, then odds are you will need to synchronize it.
--------------------------------------------------------------------------------
why do you need to synchronize it if we are to implement it into the subclass of Data??
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Kruger,
You are probably right that there is no need to synch criteriaFind in neither Data nor a subclass. All of the pertinent Data methods that would be involved in criteriaFind are already synchronized. But more importantly, criteriaFind is a non-volatile method from Data's point of view. The only possible problem that I can see is that there is rare possibility of concurrent access to Data's RandomAccessFile since writeRecord is not synchronized. Of course, since it is a private method and all public methods that call it are themselves synchronized, then the only way for that to happen is to add a public unsynchronized method to Data that calls writeRecord.
So I guess I need to backtrack and say, that it is probably unnecessary to synchronize criteriaFind in most designs.
Michael Morris
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
I did synchornize it in my submission because none of the private methods in Data are synchronized. These private methods are used by the criteriaFind method. There is a real possibility for different threads to corrupt the Collection objects used in this method if it is not synchronized. Also I had the method implemented in the Data object and not in a helper class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Should the criteriaFind be synchronized?
 
Similar Threads
The question about LOCK,UNLOCK method
Questions! Questions! Questions!
Passed
Passed 151/155
SCJD