File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes concurrent access to database row Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "concurrent access to database row" Watch "concurrent access to database row" New topic

concurrent access to database row

Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 275
Hello. I've been kinda researching how to handle concurrent access to a single row in a database...for example...if a system creates unique sequential tracking numbers, it would need to prevent (near) simultanous access to the row so the same number doesn't get assigned (and incremented) twice. I was thinking of various ways during this research and wanted to get any input on these (and additional approaches if any)...

1. shared jdbc connection with i specify the shared connection in web.xml in the <database> tag and use jndi from there in the client code? if so, would this do the trick with possible risk to performance?

2. CMP entity bean - i ultimately employed this for a previous project but i was never certain if the container handles synchronization ~and~ concurrency.

3. row lock - this makes me skiddish because the client needs to account for the condition if a row is locked...i see infinite loop potential.

any input is appreciated. thank you.
[ September 04, 2008: Message edited by: Tom Griffith ]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46389
I would try transactions first, assuming you are confident your database program handles them well.
Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 275
hello...thank you very much. I was thinking that might be the most streamlined my conclusion or whatever correct regarding shared connections...these are specified in web.xml and accessed/referenced via JNDI?

Also. i was finding another potential way via the Connection class and the transaction isolation level. Is this a viable seems kinda weird to give clients this much control over a database row. Thank you again.
I agree. Here's the link:
subject: concurrent access to database row
It's not a secret anymore!