org.apache.derbyTesting.system.oe.load
Class ThreadInsert

java.lang.Object
  extended by org.apache.derbyTesting.system.oe.load.SimpleInsert
      extended by org.apache.derbyTesting.system.oe.load.ThreadInsert
All Implemented Interfaces:
java.lang.Runnable, Load

public class ThreadInsert
extends SimpleInsert
implements java.lang.Runnable

Multi-threaded version of SimpleInsert. A number of threads execute the INSERT statements (each with their own connection). All the rows for a given warehouse are executed by one thread. The threads each get a warehouse to complete and then insert all the rows. Then they loop back to get the next warehouse. Warehouses are assigned to threads in a first come first served fashion. The main thread also inserts the ITEM table.
By default the number of threads is the number of cpus on the machine, unless the scale to be loaded is larger than the number of threads. Then the number of threads will be equal to the scale. If the scale is one or the number of threads is one then the load is just like SimpleInsert.
The number of threads can be set but if it it larger than the scale then the number of threads will be equal to the scale.
It is assumed that foreign key constraints are created after the load.


Field Summary
private  javax.sql.DataSource ds
           
private  java.sql.SQLException loadExceptions
           
private  ThreadInsert master
          The main ThreadInsert, created by the main thread and holds the valid nextWarehouse.
private  short nextWarehouse
          Next warehouse that needs to be populated.
private  int threadCount
           
 
Fields inherited from class org.apache.derbyTesting.system.oe.load.SimpleInsert
conn, random, scale, seed
 
Fields inherited from interface org.apache.derbyTesting.system.oe.client.Load
CUSTOMER_COUNT_W, DISTRICT_COUNT_W, HISTORY_COUNT_W, ITEM_COUNT, NEWORDERS_BREAKPOINT, NEWORDERS_COUNT_W, ORDERLINE_COUNT_WV, ORDERS_COUNT_W, STOCK_COUNT_W
 
Constructor Summary
  ThreadInsert(javax.sql.DataSource ds)
          Create a ThreadInsert loader.
private ThreadInsert(ThreadInsert master)
           
 
Method Summary
(package private)  void addException(java.sql.SQLException sqle)
          Save all the exceptions seen during load.
(package private)  short getNextWarehouse()
          Get the next warehouse to populate.
 void populateAllTables()
          Populate the database.
 void run()
          Run the load for a thread.
 void setThreadCount(int threadCount)
          Set the thread count.
 void setupLoad(java.sql.Connection conn, short scale)
          Initialize the load by calling the super-class's method and default the number of threads to the smaller of the number of cpus and the scale.
private  void threadPopulate()
          Populate the database using multiple threads.
 
Methods inherited from class org.apache.derbyTesting.system.oe.load.SimpleInsert
customerTable, districtTable, itemTable, orderTable, populateForOneWarehouse, setRandomGenerator, setSeed, setupConnection, stockTable, warehouseTable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

master

private final ThreadInsert master
The main ThreadInsert, created by the main thread and holds the valid nextWarehouse.


loadExceptions

private java.sql.SQLException loadExceptions

threadCount

private int threadCount

ds

private javax.sql.DataSource ds

nextWarehouse

private short nextWarehouse
Next warehouse that needs to be populated.

Constructor Detail

ThreadInsert

public ThreadInsert(javax.sql.DataSource ds)
Create a ThreadInsert loader.

Parameters:
ds - getConnection() will be used to create connections for the spaened threads.

ThreadInsert

private ThreadInsert(ThreadInsert master)
Method Detail

setupLoad

public void setupLoad(java.sql.Connection conn,
                      short scale)
               throws java.sql.SQLException
Initialize the load by calling the super-class's method and default the number of threads to the smaller of the number of cpus and the scale.

Specified by:
setupLoad in interface Load
Overrides:
setupLoad in class SimpleInsert
Parameters:
conn - - database connection
scale - - scale of the database. The WAREHOUSE table is used as the base unit of scaling.
Throws:
java.sql.SQLException

setThreadCount

public void setThreadCount(int threadCount)
Set the thread count. If the scale is less than the number of threads then the number of threads inserting data will be equal to the scale.

Specified by:
setThreadCount in interface Load
Overrides:
setThreadCount in class SimpleInsert
Parameters:
threadCount - Number of threads to use if loading supports multiple threading.

populateAllTables

public void populateAllTables()
                       throws java.lang.Exception
Populate the database.

Specified by:
populateAllTables in interface Load
Overrides:
populateAllTables in class SimpleInsert
Throws:
java.sql.SQLException
java.lang.Exception

threadPopulate

private void threadPopulate()
                     throws java.sql.SQLException,
                            java.lang.InterruptedException
Populate the database using multiple threads. The main thread (ie the one calling this method). is one of the threads that will insert the data It will handle the ITEM table by itself and its fair share of the remaining tables.

Throws:
java.sql.SQLException
java.lang.InterruptedException

getNextWarehouse

short getNextWarehouse()
Get the next warehouse to populate. If all have been populated then -1 is returned. Warehouse is one based.


addException

void addException(java.sql.SQLException sqle)
Save all the exceptions seen during load.


run

public void run()
Run the load for a thread. Loop insert the data for a single warehouse while there are warehouses left to do.

Specified by:
run in interface java.lang.Runnable

Built on Sat 2009-11-28 18:44:18-0800, from revision 885187

Apache Derby V10.6 Internals - Copyright © 2004,2008 The Apache Software Foundation. All Rights Reserved.