20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 6362121 27 * @summary Test one ScheduledThreadPoolExecutor extension scenario 28 * @author Martin Buchholz 29 */ 30 31 // based on a test kindly provided by Holger Hoffstaette <holger@wizards.de> 32 33 import java.util.concurrent.*; 34 import static java.util.concurrent.TimeUnit.MILLISECONDS; 35 36 public class ScheduledTickleService { 37 38 // We get intermittent ClassCastException if greater than 1 39 // because of calls to compareTo 40 private final static int concurrency = 2; 41 42 // Record when tasks are done 43 public final static CountDownLatch done = new CountDownLatch(concurrency); 44 45 public static void realMain(String... args) throws InterruptedException { 46 // our tickle service 47 ScheduledExecutorService tickleService = 48 new ScheduledThreadPoolExecutor(concurrency) { 49 // We override decorateTask() to return a custom 50 // RunnableScheduledFuture which explicitly removes 51 // itself from the queue after cancellation. 52 protected <V> RunnableScheduledFuture<V> 53 decorateTask(Runnable runnable, 54 RunnableScheduledFuture<V> task) { 55 final ScheduledThreadPoolExecutor exec = this; 56 return new CustomRunnableScheduledFuture<V>(task) { 57 // delegate to wrapped task, except for: 58 public boolean cancel(boolean b) { 59 // cancel wrapped task & remove myself from the queue 60 return (task().cancel(b) 61 && exec.remove(this));}};}}; 62 63 for (int i = 0; i < concurrency; i++) | 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 6362121 27 * @summary Test one ScheduledThreadPoolExecutor extension scenario 28 * @author Martin Buchholz 29 */ 30 31 // based on a test kindly provided by Holger Hoffstaette <holger@wizards.de> 32 33 import java.util.concurrent.*; 34 import static java.util.concurrent.TimeUnit.MILLISECONDS; 35 36 public class ScheduledTickleService { 37 38 // We get intermittent ClassCastException if greater than 1 39 // because of calls to compareTo 40 private static final int concurrency = 2; 41 42 // Record when tasks are done 43 public static final CountDownLatch done = new CountDownLatch(concurrency); 44 45 public static void realMain(String... args) throws InterruptedException { 46 // our tickle service 47 ScheduledExecutorService tickleService = 48 new ScheduledThreadPoolExecutor(concurrency) { 49 // We override decorateTask() to return a custom 50 // RunnableScheduledFuture which explicitly removes 51 // itself from the queue after cancellation. 52 protected <V> RunnableScheduledFuture<V> 53 decorateTask(Runnable runnable, 54 RunnableScheduledFuture<V> task) { 55 final ScheduledThreadPoolExecutor exec = this; 56 return new CustomRunnableScheduledFuture<V>(task) { 57 // delegate to wrapped task, except for: 58 public boolean cancel(boolean b) { 59 // cancel wrapped task & remove myself from the queue 60 return (task().cancel(b) 61 && exec.remove(this));}};}}; 62 63 for (int i = 0; i < concurrency; i++) |