This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC 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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "concurrent access to database row" Watch "concurrent access to database row" New topic
Author

concurrent access to database row

Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 257
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 transactions...do 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
Sheriff

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

Joined: Aug 06, 2004
Posts: 257
hello...thank you very much. I was thinking that might be the most streamlined approach...is 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 approach...it seems kinda weird to give clients this much control over a database row. Thank you again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: concurrent access to database row
 
Similar Threads
Question about shared DB connection
Single or multiple instances of Data class
getConnection throwing NotSerializableException
JDBC (ODBC) Concurrency confusion
practical applications of threads/synchronization