Package java.util.concurrent

Examples of java.util.concurrent.Future.cancel()


            } else {
                future.get();
            }
        } catch (TimeoutException e) {
            // timeout then cancel the task
            future.cancel(true);

            // signal we are forcing shutdown now, since timeout occurred
            this.forceShutdown = forceShutdown;

            // if set, stop processing and return false to indicate that the shutdown is aborting
View Full Code Here


                                                              (" "+_jbr.getString(_jbr.M_LINK)+" "+keys[0])));
                String newreq = cmd+(linkName == null ?
                                     (" "+_jbr.getString(_jbr.M_BRIDGE)+" "+_name):
                                     (" "+_jbr.getString(_jbr.M_LINK)+" "+linkName));
                if (cancelWait) {
                   if (future.cancel(true)) {
                       _logger.log(Level.WARNING, _jbr.getKString(_jbr.W_ASYNC_CMD_CANCELED, oldreq));
                   }
                }

                String emsg = _jbr.getKString(_jbr.W_ASYNC_CMD_IN_PROCESS, newreq, oldreq);
View Full Code Here

        public void run() {
            boolean execute=true;
            synchronized(tasks) {
                Future future=tasks.get(token);
                if(future != null) {
                    future.cancel(false);
                    execute=true;
                }
                else {
                    execute=false;
                }
View Full Code Here

    public void testTaskCancellationBeforeTaskHasRun() {
        Future future;
        StressTask task=new StressTask();
        future=timer.scheduleWithDynamicInterval(task);
        assertEquals(1, timer.size());
        future.cancel(true);
        assertEquals(1, timer.size());

        Util.sleep(200);
        int num_executions=task.getNum_executions();
        System.out.println("number of task executions=" + num_executions);
View Full Code Here

        StressTask task=new StressTask();
        future=timer.scheduleWithDynamicInterval(task);
        assertEquals(1, timer.size());

        Util.sleep(200); // wait until task has executed
        future.cancel(true);
        assertEquals(1, timer.size());

        int num_executions=task.getNum_executions();
        System.out.println("number of task executions=" + num_executions);
        assertTrue("task should have executed at least 1 time, as it was cancelled after 200ms", num_executions >= 1);
View Full Code Here

        RepeatingTask task=new RepeatingTask(500);
        future=timer.scheduleWithDynamicInterval(task);
        Util.sleep(5000);

        System.out.println("<<< cancelling task");
        future.cancel(true);
        Util.sleep(2000);
        int num=task.getNum();
        System.out.println("task executed " + num + " times");
        assertTrue(num >= 9 && num < 11);
    }
View Full Code Here

        for(int i=0; i < 1000; i++) {
            for(int j=0; j < 1000; j++) {
                t=new StressTask();
                Future future=timer.scheduleWithDynamicInterval(t);
                future.cancel(true);
            }
            System.out.println(i + ": " + timer.size());
        }
        for(int i=0; i < 10; i++) {
            System.out.println(timer.size());
View Full Code Here

        public void run() {
            boolean execute=true;
            synchronized(tasks) {
                Future future=tasks.get(token);
                if(future != null) {
                    future.cancel(false);
                    execute=true;
                }
                else {
                    execute=false;
                }
View Full Code Here

        public void run() {
            boolean execute=true;
            synchronized(tasks) {
                Future future=tasks.get(token);
                if(future != null) {
                    future.cancel(false);
                    execute=true;
                }
                else {
                    execute=false;
                }
View Full Code Here

      launcher.containerLauncher = mock(ExecutorService.class);
      Future future = mock(Future.class);
      when(launcher.containerLauncher.submit
          (any(Callable.class))).thenReturn(future);
      when(future.isDone()).thenReturn(false);
      when(future.cancel(false)).thenReturn(true);
      launcher.init(new Configuration());
      launcher.start();
      dispatcher.register(ContainersLauncherEventType.class, launcher);

      ctxt = mock(ContainerLaunchContext.class);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.