MCPcopy Create free account
hub / github.com/beanshell/beanshell / _measureConcurrentTime

Method _measureConcurrentTime

tests/junitTests/src/bsh/TestUtil.java:83–116  ·  view source on GitHub ↗
(final Runnable runnable, final int threadCount, final int taskCount, final int iterationCount)

Source from the content-addressed store, hash-verified

81
82
83 static long _measureConcurrentTime(final Runnable runnable, final int threadCount, final int taskCount, final int iterationCount) throws InterruptedException {
84 if (threadCount < 1) {
85 throw new IllegalArgumentException("thread count must be at least 1");
86 }
87 if (taskCount < threadCount) {
88 throw new IllegalArgumentException("task count below thread count");
89 }
90 @SuppressWarnings({"ThrowableInstanceNeverThrown"})
91 final Exception callerStack = new Exception("called from");
92 final CountDownLatch countDownLatch = new CountDownLatch(threadCount + 1);
93 final AtomicReference<Throwable> exceptionHolder = new AtomicReference<Throwable>();
94 final MeasureRunnable toMeasure = new MeasureRunnable(countDownLatch, runnable, iterationCount, exceptionHolder);
95 final ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
96 for (int i = 0; i < taskCount; i++) {
97 executorService.submit(toMeasure);
98 }
99 cleanUp();
100 final long startTime = System.nanoTime();
101 countDownLatch.countDown(); // start all
102 executorService.shutdown();
103 executorService.awaitTermination(60 * 60, TimeUnit.SECONDS);
104 final Throwable throwable = exceptionHolder.get();
105 if (throwable instanceof RuntimeException) {
106 throw combineTraces((RuntimeException) throwable, callerStack);
107 }
108 if (throwable instanceof Error) {
109 throw combineTraces((Error) throwable, callerStack);
110 }
111 if (throwable != null) {
112 //noinspection ThrowableInstanceNeverThrown
113 throw combineTraces(new RuntimeException(throwable), callerStack);
114 }
115 return System.nanoTime() - startTime;
116 }
117
118
119 /**

Callers 1

measureConcurrentTimeMethod · 0.95

Calls 3

cleanUpMethod · 0.95
combineTracesMethod · 0.95
getMethod · 0.65

Tested by

no test coverage detected