This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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 ]
I would try transactions first, assuming you are confident your database program handles them well.
Joined: Aug 06, 2004
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.