-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScheduledExecutor.java
More file actions
42 lines (42 loc) · 1.3 KB
/
Copy pathScheduledExecutor.java
File metadata and controls
42 lines (42 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//package concurrency;
//
//import java.util.concurrent.CountDownLatch;
//import java.util.concurrent.Executor;
//
//public class ScheduledExecutor {
//
// /**
// * @param args
// */
//// public static void main(String[] args) {
////
////
//// }
// // Simple framework for timing concurrent execution
// public static long time(Executor executor, int concurrency,
// final Runnable action) throws InterruptedException {
// final CountDownLatch ready = new CountDownLatch(concurrency);
// final CountDownLatch start = new CountDownLatch(1);
// final CountDownLatch done = new CountDownLatch(concurrency);
// for (int i = 0; i < concurrency; i++) {
// executor.execute(new Runnable() {
// public void run() {
// ready.countDown(); // Tell timer we're ready
// try {
// start.await(); // Wait till peers are ready
// action.run();
// } catch (InterruptedException e) {
// Thread.currentThread().interrupt();
// } finally {
// done.countDown(); // Tell timer we're done
// });
// }
// ready.await(); // Wait for all workers to be ready
// long startNanos = System.nanoTime();
// start.countDown(); // And they're off!
// done.await(); // Wait for all workers to finish
// return System.nanoTime() - startNanos;
// }
// }
//
//}