21 |
|
static class Sub implements Flow.Subscriber<Boolean> { |
22 |
|
Flow.Subscription sn; |
23 |
|
int count; |
24 |
< |
public void onSubscribe(Flow.Subscription s) { |
25 |
< |
(sn = s).request(CAP); |
24 |
> |
public void onSubscribe(Flow.Subscription s) { |
25 |
> |
(sn = s).request(CAP); |
26 |
|
} |
27 |
< |
public void onNext(Boolean t) { |
27 |
> |
public void onNext(Boolean t) { |
28 |
|
if ((++count & (CAP - 1)) == (CAP >>> 1)) |
29 |
|
sn.request(CAP); |
30 |
|
} |
31 |
|
public void onError(Throwable t) { t.printStackTrace(); } |
32 |
< |
public void onComplete() { |
32 |
> |
public void onComplete() { |
33 |
|
if (count != ITEMS) |
34 |
|
System.out.println("Error: remaining " + (ITEMS - count)); |
35 |
< |
phaser.arrive(); |
35 |
> |
phaser.arrive(); |
36 |
|
} |
37 |
|
} |
38 |
|
|
42 |
|
int reps = REPS; |
43 |
|
if (args.length > 0) |
44 |
|
reps = Integer.parseInt(args[0]); |
45 |
< |
|
46 |
< |
System.out.println("ITEMS: " + ITEMS + |
45 |
> |
|
46 |
> |
System.out.println("ITEMS: " + ITEMS + |
47 |
|
" CONSUMERS: " + CONSUMERS + |
48 |
|
" CAP: " + CAP); |
49 |
|
ExecutorService exec = ForkJoinPool.commonPool(); |
50 |
|
for (int rep = 0; rep < reps; ++reps) { |
51 |
|
long startTime = System.nanoTime(); |
52 |
< |
final SubmissionPublisher<Boolean> pub = |
52 |
> |
final SubmissionPublisher<Boolean> pub = |
53 |
|
new SubmissionPublisher<Boolean>(exec, CAP); |
54 |
|
for (int i = 0; i < CONSUMERS; ++i) |
55 |
|
pub.subscribe(new Sub()); |