I have a distributed Java application running on 5 application servers. All servers use the same Oracle 9i database running on the 6th machine.
An application must first select a package of 100 identifiers from a sequence. This is relatively easy to do in a single-threaded unallocated environment, you can simply ask these queries:
select seq.nextval from dual; alter sequence seq increment by 100; select seq.nextval from dual;
The first choice selects the first identifier of the sequence that the application can use, the second choice returns the last that can be used.
In a multi-threaded environment, things get more interesting. You cannot be sure that before the second choice, another thread will not increase the sequence by 100 again. This problem can be solved by synchronizing access on the Java side - you allow one thread to start receiving identifiers at a time.
The situation becomes very difficult when you cannot synchronize, because parts of the application do not work on the same JVM, even on the same physical machine. I found several links on forums where others have problems resolving this problem, but none of the answers work, let alone rationality.
Can the community solve the problem?
Additional Information:
- I cannot play with transaction isolation levels. I use JPA, and the change will affect the whole application, not just prefetch requests, and this is unacceptable to me.
In PostgreSQL, I could do the following:
select setval ('seq', nextval ('seq') + n - 1)
Matthew's solution works when you can use a fixed increment value (which is perfectly acceptable in my case). However, is there a solution when you do not want to fix the increment size, but want to dynamically adjust it?
java oracle
Zizzencs
source share