Java 8 ScheduledFuture - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ScheduledFuture class.

This code example shows how to use the following methods:cancel
    private double convertNsRate(double ratePerNs) {
        return ratePerNs * (double) rateUnit.toNanos(1);
    } 
 
    public void stop() { 
        future.cancel(false);
    } 
} 
8
CodeRank
This code example shows how to use the following methods:isDone
 
	@Test
	public void scheduleAndCancelHeartbeat() throws Exception {
 
		ScheduledFuture<?> task = mock(ScheduledFuture.class);
		willReturn(task).given(this.taskScheduler).schedule(any(Runnable.class), any(Date.class));
 
		this.session.setActive(true);
		this.session.scheduleHeartbeat();
 
		verify(this.taskScheduler).schedule(any(Runnable.class), any(Date.class));
		verifyNoMoreInteractions(this.taskScheduler);
 
		given(task.isDone()).willReturn(false);
 
		this.session.cancelHeartbeat();
 
		verify(task).isDone();
		verify(task).cancel(false);
		verifyNoMoreInteractions(task);

8
CodeRank
This code example shows how to use the following methods:isDone
            return this.future.isCancelled();
        } 
 
        @Override 
        public boolean isDone() { 
            return this.future.isDone();
        } 
 
        @Override 
        public T get() throws InterruptedException, ExecutionException { 
            return this.future.get();
        } 
 
        @Override 
        public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
            return this.future.get(timeout, unit);
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:cancel
		 
		component.setLogger(newLogger);
		 
		if (future1 != null) {
	 
			EasyMock.reset(future1);
			EasyMock.expect(future1.cancel(true)).andReturn(true);
			EasyMock.replay(future1);
		} 
	 
		newLogger.debug("Request " + requestID + ": Consumer [" + lwpcOID.getServiceID() + "] paused the request.");
		PeerAcceptanceUtil.replay(newLogger);
		 
		 
		LocalWorkerProvider lwp = getLocalWorkerProviderProxy();
		AcceptanceTestUtil.setExecutionContext(component, getLocalWorkerProviderDeployment(), lwpcOID);
		 
		lwp.pauseRequest(requestID);		
		 
		PeerAcceptanceUtil.verify(newLogger);

6
CodeRank
This code example shows how to use the following methods:cancel
 
    private void destroy() { 
        state = 2;
 
        if (timeout != null) {
            timeout.cancel(false);
            timeout = null;
        } 
    } 
 
    /** 
     * Is called when a read timeout was detected. 
     */ 
    protected void readTimedOut(ChannelHandlerContext ctx) throws Exception {
        if (!closed) {
            ctx.fireExceptionCaught(ReadTimeoutException.INSTANCE);
            ctx.close();
            closed = true;
        } 
    } 
6
CodeRank
This code example shows how to use the following methods:cancel
  } 
 
  @Override 
  public boolean cancel(final Exception reason)
  { 
    return _future.cancel(false);
  } 
} 
6
CodeRank
This code example shows how to use the following methods:cancel
 
	/** 
	 * 停止分发任务,如果是自行创建的threadPool则自行销毁,关闭时最多等待5秒。 
	 */ 
	public void stop() { 
		dispatchJob.cancel(false);
 
		if (internalScheduledThreadPool != null) {
			Threads.normalShutdown(internalScheduledThreadPool, 5, TimeUnit.SECONDS);
		} 
	} 
 
	/** 
	 * 以当前时间为参数执行Lua Script分发任务。 
	 */ 
	@Override 
	public void run() { 
		try { 
			long currTime = System.currentTimeMillis();
			List<String> args = Lists.newArrayList(String.valueOf(currTime), String.valueOf(reliable),
6
CodeRank
This code example shows how to use the following methods:cancel
		HttpServletRequest request, HttpServletResponse response,
		Object object) { 
 
		ScheduledFuture<?> scheduledFuture = (ScheduledFuture<?>)object;
 
		scheduledFuture.cancel(true);
	} 
 
	@Override 
	public Object doFilterTry( 
		HttpServletRequest request, HttpServletResponse response) {
 
		ScheduledFuture<?> scheduledFuture = _scheduledExecutorService.schedule(
			_threadDumper, PropsValues.THREAD_DUMP_SPEED_THRESHOLD,
			TimeUnit.SECONDS);
 
		return scheduledFuture;
	} 
 
	private static final int _MAX_THREAD_DUMPERS = 5;
5
CodeRank
This code example shows how to use the following methods:cancel
 
   @SuppressWarnings("unchecked") 
   public void testReplQueueImpl() { 
      ReplicationQueueImpl rqi = new ReplicationQueueImpl();
      ScheduledFuture sf = createMock(ScheduledFuture.class);
      expect(sf.cancel(eq(true))).andReturn(true).once();
 
      ScheduledExecutorService ses = createMock(ScheduledExecutorService.class);
      expect(ses.scheduleWithFixedDelay(EasyMock.<Runnable>anyObject(), anyLong(), anyLong(), EasyMock.<TimeUnit>anyObject()))
         .andReturn(sf).once();
 
      RpcManager rpc = createNiceMock(RpcManager.class);
      CommandsFactory commandsFactory = createNiceMock(CommandsFactory.class);
      Configuration c = new Configuration();
      c.setUseReplQueue(true);
      replay(ses, rpc, commandsFactory,sf);
 
      rqi.injectDependencies(ses, rpc, c, commandsFactory);
 
      rqi.start();

5
CodeRank
This code example shows how to use the following methods:sleep, isCancelled
public class SelfCancellingTaskTest extends TestCase {
	public void testCancel() throws Exception { 
		ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
		SelfCancellingTaskTester tester = new SelfCancellingTaskTester(5);
		ScheduledFuture<?> handle = executor.scheduleAtFixedRate(tester, 100L, 100L, TimeUnit.MILLISECONDS);
		tester.setHandle(handle);
		 
		Thread.sleep(1000L);
		 
		executor.shutdown();
		boolean terminated = executor.awaitTermination(100L, TimeUnit.MILLISECONDS);
		assertTrue(terminated);
		assertTrue(handle.isCancelled());
		assertEquals(5, tester.getRunCount());
	} 
	 
	public void testCancel_whenHandleNotImmediatelySet() throws Exception { 
		SelfCancellingTaskTester tester = new SelfCancellingTaskTester(1);
		tester.run();
		tester.run();
5
CodeRank

Related Java 8 ScheduledFuture Questions & Answers:

See Code Examples for Java 8 ScheduledFuture Methods: