Should the criteriaFind be synchronized?

Ray Cheeny

Ranch Hand

Posts: 74

posted 14 years ago

Hi, I implemented the criteriaFind in my RemoteAccess.Should I make it synchronized?

Michael Morris

Ranch Hand

Posts: 3451

posted 14 years ago

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

Posts: 39

posted 14 years ago

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

Posts: 3451

posted 14 years ago

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

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

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

Posts: 3451

posted 14 years ago

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

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

Sai Prasad

Ranch Hand

Posts: 560

posted 14 years ago

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.