Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Concurrency question
>>>>> "John" == John Bossert <jbossert_at_usa.net> writes:
John> I have a table of unique numbers, call them PINs. Once a PIN John> has been assigned to a user, it needs to be unavailable to John> other users. John> I have a query which identifies unallocated PINs. However, I John> don't know the best way to avoid the situation where twoJohn> transactions could grab the same PIN, if a second transaction John> began before the first transaction committed.
John> Is there a convention/best practice for handling this scenario? John> I'm aware of SERIALIZABLE, but am concerned about the potential John> impact on throughput.
John> Oracle 8.1.7.3.0 and 9.2.0.3.0 on Solaris 8. Client John> application is Tomcat 4.1 and java servlets.
John> Pointers appreciated.
John> -- John Bossert
John> In what concerns you much, do not think that you have John> companions: know that you are alone in the world.
John> -- Henry David Thoreau
When dealing with unique number requirements, my first choice is to use sequences. However, if you have a situation where you do not want any gaps in your sequences, then another (usually less optimal) solution is needed. Therefore, the first thing I'd do is determine if you really must re-use old PINS and whether you cannot have gaps.
One possible solution, off the top of my head and which would need refinement would be to do this.
The algorithm would be something like -
- Get pin number
-------- return SEQUENCE.NEXTVAL
-------- return first unused/missing pin
-------- return SEQUENCE.nextval - Insert pin
--------return
-------- Get SEQUENCE.nextval -------- insert pin
The idea I'm trying to express here is that first you try to re-use missing/unused pins, but if that fails get a new pin even if there may be other unused pins available. This will mean that
Tim
-- Tim Cross The e-mail address on this message is FALSE (obviously!). My real e-mail is to a company in Australia called rapttech and my login is tcross - if you really need to send mail, you should be able to work it out!Received on Sun Jun 08 2003 - 21:51:10 CDT