• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Concurrent access to records..need help ranchers..

 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have "tried" implementing the concurrent access to records.i.e Record Locking Feature in a J2EE Web based Application (or) Let us consider a simple Swings Based GUI Java Application displaying the list of records in page(s)


I'm not sure if the below Implementation is correct or not.So "Please Help me to correct it if i'm wrong anywhere in the below logic implementation.




Logic Implemented(see below):

I have implemented a rough logic for the same.Please Correct me if the logic interpretation is wrong.



Assuming i have accessed the first record "deepak",I goto this record and edit some fields in the form and click on "Submit" or "Save" button. on doing so i reset the record status back to false (i.e release the LOCK)

record.setrecord_status(false); //reset the record status to default value i.e false now. i have release the lock now and the record is available for access to another user.

Is the above implementation Correct (or) Wrong.?

Please Correct me if I'm Wrong.

Need your Help/Advice/Suggestions to resolve this issue.

--
Deepak Lal



[edit]Move code tags around. CR[/edit]
[ November 02, 2008: Message edited by: Campbell Ritchie ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 50278
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Several bits of bad design there, like the use of == and a . suggesting you have a public field.
If you need restriction of access, why don't you put the record access into a method with a Lock on?
Or better still, in a database. Then you can let the database program deal with concurrent access, or even use a transaction in the database.
 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell wrote : Several bits of bad design there, like the use of == and a . suggesting you have a public field.
If you need restriction of access, why don't you put the record access into a method with a Lock on?
Or better still, in a database. Then you can let the database program deal with concurrent access, or even use a transaction in the database.


My Comments : (see below)
Hi All,
I'm totally new to implementing the concurrent access of records.Can you please help me out with this.
I'm Sorry for the type errors regarding ==,it was not intentional..

Campbell and All,I will be highly obliged if you can help me out on how to proceed with this.

Highly

--
Deepak Lal
 
Campbell Ritchie
Sheriff
Pie
Posts: 50278
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you keep a single record as a private field of that class, then getting access to it by one user at a time can be as simple as putting synchronized as a modifier to that access method. You can lost the lock booleans.

Alternative: Make the Record object immutable by labelling all its fields final, and label the class final too. Then you can forget about concurrent access problems.
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:

Alternative: Make the Record object immutable by labelling all its fields final, and label the class final too. Then you can forget about concurrent access problems.


It escapes me.. but how will Deepak be able to "update" the record?
 
Campbell Ritchie
Sheriff
Pie
Posts: 50278
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gamini Sirisena:


It escapes me.. but how will Deepak be able to "update" the record?
Good point. If he actually wants to alter its state then it can't be immutable.
 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Totally Confused.I;m new to concurrent access of records.I was not able to grasp whatever you said.Can you please modify my code which i have pasted above and tell me whats the correct implementation.??



--
Deepak Lal
 
Campbell Ritchie
Sheriff
Pie
Posts: 50278
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your recordAccess method doesn't show how you are getting information into the record, nor how you are getting information out. All you have shown is setting a flag on the Record object.
You are passing a String and not showing how you plan to use it; you could change this to setting your Record object as immutable and replacing it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic