Java Reference
In-Depth Information
cord for the same symbol and date). The transaction handling can be further optimized in this
case by batching the inserts. When inserts are batched, the JDBC driver holds them until the
batch is completed; then all statements are transmitted in one remote JDBC call.
Here is how batching is achieved:
for
for ( int
int i = 0 ; i < numStocks ; i ++) {
while
while (! curdate . after ( endDate )) {
...
ps . addBatch (); // replaces executeUpdate() call
for
for ( int
int j = 0 ; j < 5 ; j ++) {
...
ps2 . addBatch (); // replaces executeUpdate() call
}
}
}
ps . executeBatch ();
ps2 . executeBatch ();
c . commit ();
The code could equally well choose to execute each batch on a per-stock basis (after the
while loop). Some JDBC drivers have a limitation on the number of statements they can
batch (and the batch does consume memory in the application), so even if the data is commit-
ted at the end of the entire operation, the batches may need to be executed more frequently.
These optimizations can yield very large performance increases. Table 11-1 shows the time
required to insert one year of data for 128 stocks (a total of 200,448 insertions).
Search WWH ::




Custom Search