Iam using JDBC to connect to an Oracle Table.(Table 1) Only Insertion operation is performed and Limitation is : to use \"Statement\" only.
The java
First of all a Table does not read data, some "thing" must read data from table 1 and insert it into table 2. Furthermore whatever is reading from table 1 is probably not locking all of table 1, it may lock some records, but not the whole table. Look here and here for information on how to find locks in Oracle. However:
A better option is to synchronize at a higher level; between your java code and whatever is updating Table 2.
This can be done using appropriate synchronization mechanisms (semaphores, mutexes, java locks, etc.) based on what the "thing" that updates table 2 is and what platform is being used. If specialized synchronization is not possible, you can implement the lock in the database itself.
A (very) simple such implementation uses a table lock
with columns owner
and lockID
. Each participant is then given a unique identifier and uses the following SQL statements to claim the lock:
update lock set owner =where owner is null and lockID = select owner from lock where lockID =
The owner
corresponds to the unique identifier of the participant that successfully claimed the lock.
To unclaim the lock simply set it to null
.
While simple, this approach still leaves you with the problem of figuring out when a lock becomes free, making a lock stale if it is not released (or touched) on time and possible starvation if the lock is highly contested.
An even better option if you really want to achieve near real time performance is to eliminate the database. Any database has too many variables (caches, maintenance background threads, local optimizations, etc.) to achieve consistent performance. A system that aims at near real time performance would have to use asynchronous file IO tailored to the specific platform and would probably need to use a not garbage collected language so memory allocation and deallocation can be controlled.