@@ -73,17 +73,26 @@ public TPCCLoader(TPCCBenchmark benchmark) {
7373 @ Override
7474 public List <LoaderThread > createLoaderThreads () throws SQLException {
7575 List <LoaderThread > threads = new ArrayList <LoaderThread >();
76- final CountDownLatch itemLatch = new CountDownLatch (1 );
77-
76+ int numLoaders = this .workConf .getLoaderThreads ();
77+ final CountDownLatch itemLatch = new CountDownLatch (numLoaders );
78+
7879 // ITEM
79- // This will be invoked first and executed in a single thread.
80- threads .add (new LoaderThread () {
81- @ Override
82- public void load (Connection conn ) throws SQLException {
83- loadItems (conn , TPCCConfig .configItemCount );
84- itemLatch .countDown ();
85- }
86- });
80+ // The ITEM table will be fully loaded before any other table.
81+ // Because the ITEM table is large (100k items per the TPC-C spec),
82+ // we divide the ITEM table across the maximum number of loader threads.
83+ for (int i = 1 ; i <= TPCCConfig .configItemCount ;) {
84+ int numItemsPerLoader = TPCCConfig .configItemCount / numLoaders ;
85+ int itemStartInclusive = i ;
86+ int itemEndInclusive = Math .min (TPCCConfig .configItemCount , itemStartInclusive + numItemsPerLoader - 1 );
87+ threads .add (new LoaderThread () {
88+ @ Override
89+ public void load (Connection conn ) throws SQLException {
90+ loadItems (conn , itemStartInclusive , itemEndInclusive );
91+ itemLatch .countDown ();
92+ }
93+ });
94+ i = itemEndInclusive + 1 ;
95+ }
8796
8897 // WAREHOUSES
8998 // We use a separate thread per warehouse. Each thread will load
@@ -150,7 +159,7 @@ protected void transCommit(Connection conn) {
150159 }
151160 }
152161
153- protected int loadItems (Connection conn , int itemKount ) {
162+ protected int loadItems (Connection conn , int itemStartInclusive , int itemEndInclusive ) {
154163 int k = 0 ;
155164 int randPct = 0 ;
156165 int len = 0 ;
@@ -162,7 +171,7 @@ protected int loadItems(Connection conn, int itemKount) {
162171
163172 Item item = new Item ();
164173 int batchSize = 0 ;
165- for (int i = 1 ; i <= itemKount ; i ++) {
174+ for (int i = itemStartInclusive ; i <= itemEndInclusive ; i ++) {
166175
167176 item .i_id = i ;
168177 item .i_name = TPCCUtil .randomStr (TPCCUtil .randomNumber (14 , 24 ,
0 commit comments