71 pool.shutdown(); |
71 pool.shutdown(); |
72 if (! pool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS)) |
72 if (! pool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS)) |
73 throw new Error(); |
73 throw new Error(); |
74 } |
74 } |
75 |
75 |
|
76 static final class LTQasSQ<T> extends LinkedTransferQueue<T> { |
|
77 LTQasSQ() { super(); } |
|
78 public void put(T x) { |
|
79 try { super.transfer(x); } |
|
80 catch (InterruptedException ex) { throw new Error(); } |
|
81 } |
|
82 private final static long serialVersionUID = 42; |
|
83 } |
|
84 |
|
85 static final class HalfSyncLTQ<T> extends LinkedTransferQueue<T> { |
|
86 HalfSyncLTQ() { super(); } |
|
87 public void put(T x) { |
|
88 if (ThreadLocalRandom.current().nextBoolean()) |
|
89 super.put(x); |
|
90 else { |
|
91 try { super.transfer(x); } |
|
92 catch (InterruptedException ex) { throw new Error(); } |
|
93 } |
|
94 } |
|
95 private final static long serialVersionUID = 42; |
|
96 } |
|
97 |
76 static void oneTest(int consumers, int iters) throws Exception { |
98 static void oneTest(int consumers, int iters) throws Exception { |
77 oneRun(new ArrayBlockingQueue<Integer>(CAPACITY), consumers, iters); |
99 oneRun(new ArrayBlockingQueue<Integer>(CAPACITY), consumers, iters); |
78 oneRun(new LinkedBlockingQueue<Integer>(CAPACITY), consumers, iters); |
100 oneRun(new LinkedBlockingQueue<Integer>(CAPACITY), consumers, iters); |
79 oneRun(new LinkedBlockingDeque<Integer>(CAPACITY), consumers, iters); |
101 oneRun(new LinkedBlockingDeque<Integer>(CAPACITY), consumers, iters); |
80 // oneRun(new LinkedTransferQueue<Integer>(), consumers, iters); |
102 oneRun(new LinkedTransferQueue<Integer>(), consumers, iters); |
|
103 oneRun(new LTQasSQ<Integer>(), consumers, iters); |
|
104 oneRun(new HalfSyncLTQ<Integer>(), consumers, iters); |
81 oneRun(new PriorityBlockingQueue<Integer>(), consumers, iters); |
105 oneRun(new PriorityBlockingQueue<Integer>(), consumers, iters); |
82 oneRun(new SynchronousQueue<Integer>(), consumers, iters); |
106 oneRun(new SynchronousQueue<Integer>(), consumers, iters); |
83 if (print) |
107 if (print) |
84 System.out.println("fair implementations:"); |
108 System.out.println("fair implementations:"); |
85 oneRun(new SynchronousQueue<Integer>(true), consumers, iters); |
109 oneRun(new SynchronousQueue<Integer>(true), consumers, iters); |