Package java.util.concurrent

Examples of java.util.concurrent.Future


    }


    @Test(dataProvider="createTimer")
    public void testTaskCancellationBeforeTaskHasRun(TimeScheduler timer) throws InterruptedException {
        Future future;
        StressTask task=new StressTask();
        try {
            future=timer.scheduleWithDynamicInterval(task);
            assert timer.size() == 1;
            future.cancel(true);
            assert timer.size() == 1;
            Util.sleep(200);
            int num_executions=task.getNumExecutions();
            System.out.println("number of task executions=" + num_executions);
            assert num_executions ==0 : "task should never have executed as it was cancelled before execution";
View Full Code Here


    }


    @Test(dataProvider="createTimer")
    public void testTaskCancellationAfterHasRun(TimeScheduler timer) throws InterruptedException {
        Future future;
        StressTask task=new StressTask();
        try {
            future=timer.scheduleWithDynamicInterval(task);
            assert timer.size() == 1;

            Util.sleep(500); // wait until task has executed
            future.cancel(true);
            int size=timer.size();
            assert size == 1 : " timer size should be 1, but is " + size;

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

    }


    @Test(dataProvider="createTimer")
    public void testRepeatingTask(TimeScheduler timer) throws InterruptedException {
        Future future;
        RepeatingTask task=new RepeatingTask(300);
        try {
            future=timer.scheduleAtFixedRate(task, 0, 300, TimeUnit.MILLISECONDS);
            Util.sleep(3200);

            System.out.println("<<< cancelling task");
            future.cancel(true);
            Util.sleep(1000);
            int num=task.getNum();
            System.out.println("task executed " + num + " times");
           
            assert num >= 8 && num <= 11 : "number of executions is " + num + ", but should be >= 8 and <= 11\n" +
View Full Code Here

        try {
            System.out.println("-- adding "+ (NUM_A * NUM_B) + " tasks...");
            for(int i=0; i < NUM_A; i++) {
                for(int j=0; j < NUM_B; j++) {
                    t=new StressTask();
                    Future future=timer.scheduleWithDynamicInterval(t);
                    future.cancel(true);
                    cnt++;
                    if(cnt > 0 && cnt % print == 0)
                        System.out.println(cnt);
                }
            }
View Full Code Here

        public synchronized void resume(MergeId merge_id) {
            if(!suspended)
                return;

            Future future;
            synchronized(resume_tasks) {
                future=resume_tasks.remove(merge_id);
            }
            if(future != null)
                future.cancel(true);
            resumeForce();
        }
View Full Code Here

}

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

      final ExecutorService executor = Executors.newFixedThreadPool(2);
      final CountDownLatch pushStateCanFinish = new CountDownLatch(1);
      final CountDownLatch secondActiveStatusChangerCanStart = new CountDownLatch(1);
      final MockSingletonStoreCacheLoader mscl = new MockSingletonStoreCacheLoader(pushStateCanFinish, secondActiveStatusChangerCanStart, new SingletonStoreDefaultConfig());

      Future f1 = executor.submit(createActiveStatusChanger(mscl));
      secondActiveStatusChangerCanStart.await();

      Future f2 = executor.submit(createActiveStatusChanger(mscl));

      f1.get();
      f2.get();

      assertEquals(1, mscl.getNumberCreatedTasks());
   }
View Full Code Here

      final CountDownLatch pushStateCanFinish = new CountDownLatch(1);
      SingletonStoreDefaultConfig ssdc = new SingletonStoreDefaultConfig();
      ssdc.setPushStateWhenCoordinatorTimeout(1000);
      final MockSingletonStoreCacheLoader mscl = new MockSingletonStoreCacheLoader(pushStateCanFinish, null, ssdc);

      Future f = Executors.newSingleThreadExecutor().submit(createActiveStatusChanger(mscl));
      pushStateCanFinish.await(2000, TimeUnit.MILLISECONDS);
      pushStateCanFinish.countDown();

      try
      {
         f.get();
         fail("Should have timed out");
      }
      catch (ExecutionException e)
      {
         Throwable t = e.getCause().getCause().getCause();
View Full Code Here

        String expected2 = "Hello TestSOAPInputMessage2";
        assertEquals("Response should be : Hello TestSOAPInputMessage2",
                     expected2, soapResMsg2.getSOAPBody().getTextContent());
       
        TestSOAPMessageHandler tsmh = new TestSOAPMessageHandler();
        Future f = disp.invokeAsync(soapReqMsg3, tsmh);
        assertNotNull(f);
        while (!f.isDone()) {
            //wait
        }
        String expected3 = "Hello TestSOAPInputMessage3";
        assertEquals("Response should be : Hello TestSOAPInputMessage3",
                     expected3, tsmh.getReplyBuffer());
View Full Code Here

        assertEquals("Response should be : Hello TestSOAPInputMessage2",
                     expected2, domRespMsg2.getNode().getFirstChild().getTextContent());
       
       
        TestDOMSourceHandler tdsh = new TestDOMSourceHandler();
        Future fd = disp.invokeAsync(domReqMsg3, tdsh);
        assertNotNull(fd);
        while (!fd.isDone()) {
            //wait
        }
        String expected3 = "Hello TestSOAPInputMessage3";
        assertEquals("Response should be : Hello TestSOAPInputMessage3",
                     expected3, tdsh.getReplyBuffer());
View Full Code Here

TOP

Related Classes of java.util.concurrent.Future

Copyright © 2018 www.massapicom. 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.