使用する必要があるスレッドの数を渡すプロジェクトの作業を開始しました。次に、実行にかかる時間を測定しようとしますSELECT sql
。そのために、この行の直前にカウンターpreparedStatement.executeQuery();
とカウンターがあります。この行の後の時間を測定します。
以下は私のコードのスニペットです-
public class TestPool {
public static void main(String[] args) {
final int no_of_threads = 10;
// create thread pool with given size
ExecutorService service = Executors.newFixedThreadPool(no_of_threads);
// queue some tasks
for(int i = 0; i < 3 * no_of_threads; i++) {
service.submit(new ThreadTask());
}
// wait for termination
service.shutdown();
service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
// Now print the select histogram here
System.out.println(ThreadTask.selectHistogram);
}
}
以下は、Runnable インターフェイスを実装する私の ThreadTask クラスです。
class ThreadTask implements Runnable {
private PreparedStatement preparedStatement = null;
private ResultSet rs = null;
public static ConcurrentHashMap<Long, AtomicLong> selectHistogram = new ConcurrentHashMap<Long, AtomicLong>();
public ThreadTask() {
}
@Override
public void run() {
...........
long start = System.nanoTime();
rs = preparedStatement.executeQuery();
long end = System.nanoTime() - start;
final AtomicLong before = selectHistogram.putIfAbsent(end / 1000000L, new AtomicLong(1L));
if (before != null) {
before.incrementAndGet();
}
..............
}
}
問題文:-
今日、私は設計会議を開きました。ほとんどの人は、プログラムを実行したらすぐに時間の測定を開始しないと言いました。ウォームアップ期間を設けてから、測定を開始します。それで、それをするのは理にかなっていると思いました。そして今、その変更をコードにどのように組み込むべきかを考えています。私はこれを何に基づいて行うのでしょうか?誰でも何か提案できますか?