34 |
static ThreadPoolExecutor threadPool; |
static ThreadPoolExecutor threadPool; |
35 |
|
|
36 |
private static void setupThreadPool() { |
private static void setupThreadPool() { |
37 |
threadPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(max_workers, new ThreadFactory() { |
threadPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(max_workers, new WorkerThreadFactory() ); |
|
@Override |
|
|
public Thread newThread(Runnable r) { |
|
|
return new Thread(r, "lookupWorker"); |
|
|
} |
|
|
}); |
|
38 |
} |
} |
39 |
|
|
40 |
|
|
141 |
Lookup lookup = new Lookup("458x", db, threadPool); |
Lookup lookup = new Lookup("458x", db, threadPool); |
142 |
lookup.doLookup(); |
lookup.doLookup(); |
143 |
} |
} |
144 |
|
|
145 |
|
threadPool.shutdown(); |
146 |
|
|
147 |
long now = System.currentTimeMillis(); |
long now = System.currentTimeMillis(); |
148 |
long elapsed = now - start ; |
long elapsed = now - start ; |
179 |
int hours = (int) ((milliseconds / (1000*60*60)) % 24); |
int hours = (int) ((milliseconds / (1000*60*60)) % 24); |
180 |
|
|
181 |
return String.format("%02d:%02d:%02d.%03d", hours, minutes, seconds, mseconds); |
return String.format("%02d:%02d:%02d.%03d", hours, minutes, seconds, mseconds); |
182 |
} |
} |
183 |
|
|
184 |
|
static class WorkerThreadFactory implements ThreadFactory { |
185 |
|
int count = 0; |
186 |
|
|
187 |
|
@Override |
188 |
|
public Thread newThread(Runnable r) { |
189 |
|
return new Thread(r, "lookupWorker/" + count++); |
190 |
|
} |
191 |
|
} |
192 |
} |
} |