File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Concurrent access to records..need help ranchers.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Concurrent access to records..need help ranchers.." Watch "Concurrent access to records..need help ranchers.." New topic
Author

Concurrent access to records..need help ranchers..

Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

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 ]

When The Going Gets Tougher,The Tougher gets Going
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39385
    
  28
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

Joined: Jul 01, 2008
Posts: 507


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

Joined: Oct 13, 2005
Posts: 39385
    
  28
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

Joined: Aug 05, 2008
Posts: 347
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

Joined: Oct 13, 2005
Posts: 39385
    
  28
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

Joined: Jul 01, 2008
Posts: 507

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

Joined: Oct 13, 2005
Posts: 39385
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Concurrent access to records..need help ranchers..