• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

locking and synchronization question

 
jesal dosa
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been reading some of the posts on locking and I just want to ask a couple of questions for a sanity check.

my DBMain interface class has the standard methods.


Question 1I need to make this synchronized so my first question is in my Data class when i implement the DBMain interface class if i put synchronized in the method definition is that valid and not a automatic failure. I know i could implement this by reentrant locking but i don't want to go down that route



Question 2 I have lock and unlock methods in my DBMain interface but I want to use a locking class for the record locking.
a) can i ignore the locking methods in the interface i.e leave them empty
b) l have followed the classic example of a service interface containing a search and book method. Can i get way with just having locking implemented in the book method. I have two concrete classes implementing the service interface. The remoteServiceImp class and a ServiceImp class. The serivceImp contains the actual code for the search and book methods and the remoteSerivceImp just make a call to the serviceImp. ie



could i put the locking code in the remoteServicesImp ie
; before services.book and ; after services.book
or do i need to rewrite the remoteServicesImp booking methods and add the locking during the data.read and data.find bits. i prefer the lazy way of calling the service.book method at the moment

Sorry for turning this into a essay but i hope you guys can help.
 
jesal dosa
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I seem to have found the answer to question 1
can sync data methods

So its fine to synchronize the read method. I hope so one can give me ideas about question 2
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jesal dosa wrote:I seem to have found the answer to question 1
can sync data methods

So its fine to synchronize the read method. I hope so one can give me ideas about question 2



Question 2 I have lock and unlock methods in my DBMain interface but I want to use a locking class for the record locking.
a) can i ignore the locking methods in the interface i.e leave them empty
b) l have followed the classic example of a service interface containing a search and book method. Can i get way with just having locking implemented in the book method. I have two concrete classes implementing the service interface. The remoteServiceImp class and a ServiceImp class. The serivceImp contains the actual code for the search and book methods and the remoteSerivceImp just make a call to the serviceImp. ie



My understanding is that SUN can take your implementation of DBMain, use a single method and see if it reacts according to the contract. If your lock method does nothing, it does not do what it should be doing according to the contract.

Why don't you use your locking class from your lock/unlock method ?

Alex



Regards,
Alex
 
jesal dosa
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alex,

I thought the locking should be separated from the data class. Also locking is not required for standalone mode. Actually what you say seems very logically.

A following on question then. I was only going to put locking in my business layer i.e. in the service implementation class specifically in the booking method.

So rather than but the locking there i could put record locking in the update method in the data class but then there would be record locking even in the standalone mode where record locking is not required.

I hope I am making some sense

Thanks for your help
 
Anne Crace
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alex is right. Call your Locking Manager from Data lock()/unlock(). Ideally, yes, you might like to do the locking from the business layer, but you have to honor that interface, so you need to do it from Data. Mine goes something like this: Controller(Business)-->Data-->LockManager. I think most people leave the locking in the standalone. It doesn't hurt anything, it's just not necessary. Hope this helps.
 
jesal dosa
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Anne,

If you guys think its fine to leave the locking in during the standalone mode, then that seems acceptable to me as well. Thanks for you advice.

Ok then i will implement my locking in the data class. and will keep record locking even in standalone mode and as per per my previous reply i will use synchronized when implementing the DBmain interface in the data class
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jesal dosa wrote:Thanks Anne,

If you guys think its fine to leave the locking in during the standalone mode, then that seems acceptable to me as well. Thanks for you advice.

Ok then i will implement my locking in the data class. and will keep record locking even in standalone mode and as per per my previous reply i will use synchronized when implementing the DBmain interface in the data class


I agree with other ranchers..

You should view your DBMain implementation as a persistence library that your application will be using.. Similar to any other product in the java world, SUN provides an interface, a 3rd party company provide the implementation and the developers use the implementation.

In other words, the "3rd party company" (you) must provide a correct implementation so that the "developer" (you) can use it as expected.

Regards,
Alex
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic