java.util.concurrent.RunnableScheduledFuture Java Examples

The following examples show how to use java.util.concurrent.RunnableScheduledFuture. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractDominoExecutor.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
protected <V> RunnableScheduledFuture<V> queue(final RunnableScheduledFuture<V> future) {
	if (isShutdown()) {
		throw new RejectedExecutionException();
	}
	if (getPoolSize() < getCorePoolSize()) {
		prestartCoreThread();
	}

	if (future instanceof DominoFutureTask) {
		DominoFutureTask<?> dft = (DominoFutureTask<?>) future;
		tasks.put(dft.sequenceNumber, dft);
		if (dft.getDelay(TimeUnit.NANOSECONDS) > 0) {
			dft.setState(TaskState.SLEEPING);
		}
	}
	super.getQueue().add(future);
	return future;
}
 
Example #2
Source File: ScheduledTickleService.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void realMain(String... args) throws InterruptedException {
    // our tickle service
    ScheduledExecutorService tickleService =
        new ScheduledThreadPoolExecutor(concurrency) {
            // We override decorateTask() to return a custom
            // RunnableScheduledFuture which explicitly removes
            // itself from the queue after cancellation.
            protected <V> RunnableScheduledFuture<V>
                decorateTask(Runnable runnable,
                             RunnableScheduledFuture<V> task) {
                final ScheduledThreadPoolExecutor exec = this;
                return new CustomRunnableScheduledFuture<V>(task) {
                    // delegate to wrapped task, except for:
                    public boolean cancel(boolean b) {
                        // cancel wrapped task & remove myself from the queue
                        return (task().cancel(b)
                                && exec.remove(this));}};}};

    for (int i = 0; i < concurrency; i++)
        new ScheduledTickle(i, tickleService)
            .setUpdateInterval(25, MILLISECONDS);

    done.await();
    tickleService.shutdown();
    pass();
}
 
Example #3
Source File: TrackingScheduledExecutor.java    From quarks with Apache License 2.0 6 votes vote down vote up
/**
 * Determines whether there are tasks which have started and not completed.
 * 
 * As a side effect, this method removes all tasks which are done but are
 * still in the tracking list.
 * 
 * @return {@code true} is active tasks exist.
 */
public boolean hasActiveTasks() {
    boolean doesHaveTasks = false; 
    synchronized (asyncTasks) {
        if (asyncTasks.isEmpty())
            return false;
        
        Iterator<RunnableScheduledFuture<?>> i = asyncTasks.iterator();
        while (i.hasNext()) {
            RunnableScheduledFuture<?> task = i.next();
            if (task.isDone())
                 i.remove();
            else
                doesHaveTasks = true;
        }
    }
    return doesHaveTasks;
}
 
Example #4
Source File: SafeEnhancedScheduledTaskExecutor.java    From super-cloudops with Apache License 2.0 6 votes vote down vote up
/**
 * @see {@link java.util.concurrent.ScheduledThreadPoolExecutor.ScheduledFutureTask}
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected <V> RunnableScheduledFuture<V> decorateTask(Runnable runnable, RunnableScheduledFuture<V> task) {
	if (runnable instanceof RandomScheduleRunnable) {
		try {
			return new CustomScheduledFutureTask<V>((Callable) callableField.get(task), (long) timeField.get(task), this) {
				@Override
				public long getPeriod() {
					return ((RandomScheduleRunnable) runnable).nextDelay();
				}
			};
		} catch (Exception e) {
			throw new IllegalStateException(e);
		}
	}
	return task;
}
 
Example #5
Source File: NonblockingScheduledExecutor.java    From bt with Apache License 2.0 5 votes vote down vote up
void doStateMaintenance() {
	
	while(!isShutdown()) {
		RunnableScheduledFuture<?> toSchedule;
		while((toSchedule = submittedScheduledTasks.poll()) != null)
			delayedTasks.add(toSchedule);
		RunnableScheduledFuture<?> toExecute;
		while((toExecute = delayedTasks.peek()) != null && toExecute.getDelay(TimeUnit.NANOSECONDS) <= 0) {
			delayedTasks.poll();
			immediateExecutor.executeWithoutWakeup(toExecute);
		}
		
		RunnableScheduledFuture<?> nextTask = delayedTasks.peek();

		// signal current thread as suspended before we actually check work queues.
		// this avoids wakeupWaiter() seeing an inconsistent state
		currentSleeper.set(Thread.currentThread());

		if(executorQueue.isEmpty() && submittedScheduledTasks.isEmpty()) {
			if(nextTask != null)
				LockSupport.parkNanos(nextTask.getDelay(TimeUnit.NANOSECONDS));
			else
				LockSupport.park();
			currentSleeper.set(null);
		} else {
			currentSleeper.set(null);
			// there are unmatched tasks in the queue, return this thread to the pool
			break;
		}
	}
	
	
	// reschedule if we fall out of loop
	if(!isShutdown())
		immediateExecutor.executeWithoutWakeup(scheduler);
}
 
Example #6
Source File: LazyTraceScheduledThreadPoolExecutor.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <V> RunnableScheduledFuture<V> decorateTask(Callable<V> callable,
		RunnableScheduledFuture<V> task) {
	return (RunnableScheduledFuture<V>) ReflectionUtils.invokeMethod(
			this.decorateTaskCallable, this.delegate,
			new TraceCallable<>(tracing(), spanNamer(), callable), task);
}
 
Example #7
Source File: TrackingScheduledExecutor.java    From quarks with Apache License 2.0 5 votes vote down vote up
private int cancelAllAsyncTasks(boolean mayInterruptIfRunning) {
    int notCanceled = 0;
    synchronized (asyncTasks) {
        for (RunnableScheduledFuture<?> task : asyncTasks) {
            if (!task.cancel(mayInterruptIfRunning))
                notCanceled++;
        }
        // remove tasks which are done
        hasActiveTasks();
    }
    return notCanceled;
}
 
Example #8
Source File: MetricSafeScheduledExecutorService.java    From datacollector with Apache License 2.0 5 votes vote down vote up
public MetricsTask(RunnableScheduledFuture<V> delegate) {
  this.delegate = delegate;
  if(isPeriodic()) {
    ((AtomicInteger) gaugeMap.get(KEY_PERIODIC_COUNT)).incrementAndGet();
  } else {
    ((AtomicInteger) gaugeMap.get(KEY_WAITING_COUNT)).incrementAndGet();
  }
}
 
Example #9
Source File: NonblockingScheduledExecutor.java    From mldht with Mozilla Public License 2.0 5 votes vote down vote up
void doStateMaintenance() {
	
	while(!isShutdown()) {
		RunnableScheduledFuture<?> toSchedule;
		while((toSchedule = submittedScheduledTasks.poll()) != null)
			delayedTasks.add(toSchedule);
		RunnableScheduledFuture<?> toExecute;
		while((toExecute = delayedTasks.peek()) != null && toExecute.getDelay(TimeUnit.NANOSECONDS) <= 0) {
			delayedTasks.poll();
			immediateExecutor.executeWithoutWakeup(toExecute);
		}
		
		RunnableScheduledFuture<?> nextTask = delayedTasks.peek();

		// signal current thread as suspended before we actually check work queues.
		// this avoids wakeupWaiter() seeing an inconsistent state
		currentSleeper.set(Thread.currentThread());

		if(executorQueue.isEmpty() && submittedScheduledTasks.isEmpty()) {
			if(nextTask != null)
				LockSupport.parkNanos(nextTask.getDelay(TimeUnit.NANOSECONDS));
			else
				LockSupport.park();
			currentSleeper.set(null);
		} else {
			currentSleeper.set(null);
			// there are unmatched tasks in the queue, return this thread to the pool
			break;
		}
	}
	
	
	// reschedule if we fall out of loop
	if(!isShutdown())
		immediateExecutor.executeWithoutWakeup(scheduler);
}
 
Example #10
Source File: LoggingScheduledThreadPoolExecutor.java    From openAGV with Apache License 2.0 5 votes vote down vote up
private boolean isPeriodic(Future<?> future) {
  if (future instanceof RunnableScheduledFuture<?>) {
    RunnableScheduledFuture<?> runnableFuture = (RunnableScheduledFuture<?>) future;
    if (runnableFuture.isPeriodic()) {
      return true;
    }
  }
  return false;
}
 
Example #11
Source File: SchedulersTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
boolean isAllTasksCancelled() {
	for(RunnableScheduledFuture<?> task: tasks) {
		if (!task.isCancelled()) {
			return false;
		}
	}
	return true;
}
 
Example #12
Source File: SchedulersTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
boolean isAllTasksCancelledOrDone() {
	for(RunnableScheduledFuture<?> task: tasks) {
		if (!task.isCancelled() && !task.isDone()) {
			return false;
		}
	}
	return true;
}
 
Example #13
Source File: LazyTraceScheduledThreadPoolExecutor.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
LazyTraceScheduledThreadPoolExecutor(int corePoolSize, BeanFactory beanFactory,
		ScheduledThreadPoolExecutor delegate) {
	super(corePoolSize);
	this.beanFactory = beanFactory;
	this.delegate = delegate;
	this.decorateTaskRunnable = ReflectionUtils.findMethod(
			ScheduledThreadPoolExecutor.class, "decorateTask", Runnable.class,
			RunnableScheduledFuture.class);
	makeAccessibleIfNotNull(this.decorateTaskRunnable);
	this.decorateTaskCallable = ReflectionUtils.findMethod(
			ScheduledThreadPoolExecutor.class, "decorateTaskCallable", Callable.class,
			RunnableScheduledFuture.class);
	makeAccessibleIfNotNull(this.decorateTaskCallable);
	this.finalize = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
			"finalize", null);
	makeAccessibleIfNotNull(this.finalize);
	this.beforeExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
			"beforeExecute", null);
	makeAccessibleIfNotNull(this.beforeExecute);
	this.afterExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
			"afterExecute", null);
	makeAccessibleIfNotNull(this.afterExecute);
	this.terminated = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
			"terminated", null);
	makeAccessibleIfNotNull(this.terminated);
	this.newTaskForRunnable = ReflectionUtils.findMethod(
			ScheduledThreadPoolExecutor.class, "newTaskFor", Runnable.class,
			Object.class);
	makeAccessibleIfNotNull(this.newTaskForRunnable);
	this.newTaskForCallable = ReflectionUtils.findMethod(
			ScheduledThreadPoolExecutor.class, "newTaskFor", Callable.class,
			Object.class);
	makeAccessibleIfNotNull(this.newTaskForCallable);
}
 
Example #14
Source File: LazyTraceScheduledThreadPoolExecutor.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
LazyTraceScheduledThreadPoolExecutor(int corePoolSize, ThreadFactory threadFactory,
		BeanFactory beanFactory, ScheduledThreadPoolExecutor delegate) {
	super(corePoolSize, threadFactory);
	this.beanFactory = beanFactory;
	this.delegate = delegate;
	this.decorateTaskRunnable = ReflectionUtils.findMethod(
			ScheduledThreadPoolExecutor.class, "decorateTask", Runnable.class,
			RunnableScheduledFuture.class);
	makeAccessibleIfNotNull(this.decorateTaskRunnable);
	this.decorateTaskCallable = ReflectionUtils.findMethod(
			ScheduledThreadPoolExecutor.class, "decorateTaskCallable", Callable.class,
			RunnableScheduledFuture.class);
	makeAccessibleIfNotNull(this.decorateTaskCallable);
	this.finalize = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
			"finalize");
	makeAccessibleIfNotNull(this.finalize);
	this.beforeExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
			"beforeExecute");
	makeAccessibleIfNotNull(this.beforeExecute);
	this.afterExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
			"afterExecute", null);
	makeAccessibleIfNotNull(this.afterExecute);
	this.terminated = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
			"terminated", null);
	makeAccessibleIfNotNull(this.terminated);
	this.newTaskForRunnable = ReflectionUtils.findMethod(
			ScheduledThreadPoolExecutor.class, "newTaskFor", Runnable.class,
			Object.class);
	makeAccessibleIfNotNull(this.newTaskForRunnable);
	this.newTaskForCallable = ReflectionUtils.findMethod(
			ScheduledThreadPoolExecutor.class, "newTaskFor", Callable.class,
			Object.class);
	makeAccessibleIfNotNull(this.newTaskForCallable);
}
 
Example #15
Source File: LazyTraceScheduledThreadPoolExecutor.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
LazyTraceScheduledThreadPoolExecutor(int corePoolSize,
		RejectedExecutionHandler handler, BeanFactory beanFactory,
		ScheduledThreadPoolExecutor delegate) {
	super(corePoolSize, handler);
	this.beanFactory = beanFactory;
	this.delegate = delegate;
	this.decorateTaskRunnable = ReflectionUtils.findMethod(
			ScheduledThreadPoolExecutor.class, "decorateTask", Runnable.class,
			RunnableScheduledFuture.class);
	makeAccessibleIfNotNull(this.decorateTaskRunnable);
	this.decorateTaskCallable = ReflectionUtils.findMethod(
			ScheduledThreadPoolExecutor.class, "decorateTaskCallable", Callable.class,
			RunnableScheduledFuture.class);
	makeAccessibleIfNotNull(this.decorateTaskCallable);
	this.finalize = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
			"finalize", null);
	makeAccessibleIfNotNull(this.finalize);
	this.beforeExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
			"beforeExecute", null);
	makeAccessibleIfNotNull(this.beforeExecute);
	this.afterExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
			"afterExecute", null);
	makeAccessibleIfNotNull(this.afterExecute);
	this.terminated = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
			"terminated", null);
	makeAccessibleIfNotNull(this.terminated);
	this.newTaskForRunnable = ReflectionUtils.findMethod(
			ScheduledThreadPoolExecutor.class, "newTaskFor", Runnable.class,
			Object.class);
	makeAccessibleIfNotNull(this.newTaskForRunnable);
	this.newTaskForCallable = ReflectionUtils.findMethod(
			ScheduledThreadPoolExecutor.class, "newTaskFor", Callable.class,
			Object.class);
	makeAccessibleIfNotNull(this.newTaskForCallable);
}
 
Example #16
Source File: LazyTraceScheduledThreadPoolExecutor.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
LazyTraceScheduledThreadPoolExecutor(int corePoolSize, ThreadFactory threadFactory,
		RejectedExecutionHandler handler, BeanFactory beanFactory,
		ScheduledThreadPoolExecutor delegate) {
	super(corePoolSize, threadFactory, handler);
	this.beanFactory = beanFactory;
	this.delegate = delegate;
	this.decorateTaskRunnable = ReflectionUtils.findMethod(
			ScheduledThreadPoolExecutor.class, "decorateTask", Runnable.class,
			RunnableScheduledFuture.class);
	makeAccessibleIfNotNull(this.decorateTaskRunnable);
	this.decorateTaskCallable = ReflectionUtils.findMethod(
			ScheduledThreadPoolExecutor.class, "decorateTaskCallable", Callable.class,
			RunnableScheduledFuture.class);
	makeAccessibleIfNotNull(this.decorateTaskCallable);
	this.finalize = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
			"finalize", null);
	makeAccessibleIfNotNull(this.finalize);
	this.beforeExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
			"beforeExecute", null);
	makeAccessibleIfNotNull(this.beforeExecute);
	this.afterExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
			"afterExecute", null);
	makeAccessibleIfNotNull(this.afterExecute);
	this.terminated = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
			"terminated");
	makeAccessibleIfNotNull(this.terminated);
	this.newTaskForRunnable = ReflectionUtils.findMethod(
			ScheduledThreadPoolExecutor.class, "newTaskFor", Runnable.class,
			Object.class);
	makeAccessibleIfNotNull(this.newTaskForRunnable);
	this.newTaskForCallable = ReflectionUtils.findMethod(
			ScheduledThreadPoolExecutor.class, "newTaskFor", Callable.class,
			Object.class);
	makeAccessibleIfNotNull(this.newTaskForCallable);
}
 
Example #17
Source File: LazyTraceScheduledThreadPoolExecutor.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <V> RunnableScheduledFuture<V> decorateTask(Runnable runnable,
		RunnableScheduledFuture<V> task) {
	return (RunnableScheduledFuture<V>) ReflectionUtils.invokeMethod(
			this.decorateTaskRunnable, this.delegate,
			new TraceRunnable(tracing(), spanNamer(), runnable), task);
}
 
Example #18
Source File: LazyTraceScheduledThreadPoolExecutor.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@Override
  @SuppressWarnings("unchecked")
  public <V> RunnableScheduledFuture<V> decorateTask(
          Callable<V> callable,
          RunnableScheduledFuture<V> task) {
return (RunnableScheduledFuture<V>) ReflectionUtils.invokeMethod(
		this.decorateTaskCallable,
		this.delegate,
		TraceCallable.wrap(callable),
		task);
  }
 
Example #19
Source File: LazyTraceScheduledThreadPoolExecutor.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@Override
  @SuppressWarnings("unchecked")
  public <V> RunnableScheduledFuture<V> decorateTask(
          Runnable runnable,
          RunnableScheduledFuture<V> task) {
return (RunnableScheduledFuture<V>) ReflectionUtils.invokeMethod(
		this.decorateTaskRunnable,
		this.delegate,
		TraceRunnable.wrap(runnable),
		task);
  }
 
Example #20
Source File: LazyTraceScheduledThreadPoolExecutor.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
LazyTraceScheduledThreadPoolExecutor(
         int corePoolSize,
ThreadFactory threadFactory,
         RejectedExecutionHandler handler,
         ScheduledThreadPoolExecutor delegate) {
     super(corePoolSize, threadFactory, handler);
     this.delegate = delegate;
     this.decorateTaskRunnable = ReflectionUtils.findMethod(
             ScheduledThreadPoolExecutor.class, "decorateTask", Runnable.class,
             RunnableScheduledFuture.class);
     makeAccessibleIfNotNull(this.decorateTaskRunnable);
     this.decorateTaskCallable = ReflectionUtils.findMethod(
             ScheduledThreadPoolExecutor.class, "decorateTaskCallable", Callable.class,
             RunnableScheduledFuture.class);
     makeAccessibleIfNotNull(this.decorateTaskCallable);
     this.finalize = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
             "finalize", null);
     makeAccessibleIfNotNull(this.finalize);
     this.beforeExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
             "beforeExecute", null);
     makeAccessibleIfNotNull(this.beforeExecute);
     this.afterExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
             "afterExecute", null);
     makeAccessibleIfNotNull(this.afterExecute);
     this.terminated = ReflectionUtils.findMethod(
             ScheduledThreadPoolExecutor.class,
             "terminated");
     makeAccessibleIfNotNull(this.terminated);
     this.newTaskForRunnable = ReflectionUtils.findMethod(
             ScheduledThreadPoolExecutor.class, "newTaskFor", Runnable.class,
             Object.class);
     makeAccessibleIfNotNull(this.newTaskForRunnable);
     this.newTaskForCallable = ReflectionUtils.findMethod(
             ScheduledThreadPoolExecutor.class, "newTaskFor", Callable.class,
             Object.class);
     makeAccessibleIfNotNull(this.newTaskForCallable);
 }
 
Example #21
Source File: RollScheduledExecutor.java    From emissary with Apache License 2.0 5 votes vote down vote up
@Override
protected <V> RunnableScheduledFuture<V> decorateTask(Runnable runnable, RunnableScheduledFuture<V> task) {
    if (runnable instanceof Roller) {
        return new RollFuture<>(task, (Roller) runnable);
    } else {
        return super.decorateTask(runnable, task);
    }
}
 
Example #22
Source File: LazyTraceScheduledThreadPoolExecutor.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
LazyTraceScheduledThreadPoolExecutor(
        int corePoolSize,
        RejectedExecutionHandler handler,
        ScheduledThreadPoolExecutor delegate) {
    super(corePoolSize, handler);
    this.delegate = delegate;
    this.decorateTaskRunnable = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class, "decorateTask", Runnable.class,
            RunnableScheduledFuture.class);
    makeAccessibleIfNotNull(this.decorateTaskRunnable);
    this.decorateTaskCallable = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class, "decorateTaskCallable", Callable.class,
            RunnableScheduledFuture.class);
    makeAccessibleIfNotNull(this.decorateTaskCallable);
    this.finalize = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
            "finalize", null);
    makeAccessibleIfNotNull(this.finalize);
    this.beforeExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
            "beforeExecute", null);
    makeAccessibleIfNotNull(this.beforeExecute);
    this.afterExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
            "afterExecute", null);
    makeAccessibleIfNotNull(this.afterExecute);
    this.terminated = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
            "terminated", null);
    makeAccessibleIfNotNull(this.terminated);
    this.newTaskForRunnable = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class, "newTaskFor", Runnable.class,
            Object.class);
    makeAccessibleIfNotNull(this.newTaskForRunnable);
    this.newTaskForCallable = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class, "newTaskFor", Callable.class,
            Object.class);
    makeAccessibleIfNotNull(this.newTaskForCallable);
}
 
Example #23
Source File: LazyTraceScheduledThreadPoolExecutor.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
LazyTraceScheduledThreadPoolExecutor(
        int corePoolSize,
        ThreadFactory threadFactory,
        ScheduledThreadPoolExecutor delegate) {
    super(corePoolSize, threadFactory);
    this.delegate = delegate;
    this.decorateTaskRunnable = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class, "decorateTask", Runnable.class,
            RunnableScheduledFuture.class);
    makeAccessibleIfNotNull(this.decorateTaskRunnable);
    this.decorateTaskCallable = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class, "decorateTaskCallable", Callable.class,
            RunnableScheduledFuture.class);
    makeAccessibleIfNotNull(this.decorateTaskCallable);
    this.finalize = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class,
            "finalize");
    makeAccessibleIfNotNull(this.finalize);
    this.beforeExecute = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class,
            "beforeExecute");
    makeAccessibleIfNotNull(this.beforeExecute);
    this.afterExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
            "afterExecute", null);
    makeAccessibleIfNotNull(this.afterExecute);
    this.terminated = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
            "terminated", null);
    makeAccessibleIfNotNull(this.terminated);
    this.newTaskForRunnable = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class, "newTaskFor", Runnable.class,
            Object.class);
    makeAccessibleIfNotNull(this.newTaskForRunnable);
    this.newTaskForCallable = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class, "newTaskFor", Callable.class,
            Object.class);
    makeAccessibleIfNotNull(this.newTaskForCallable);
}
 
Example #24
Source File: TestThreadPoolPublishModelFactory.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void createDefaultPublishModel() throws JsonProcessingException {
  new Expectations() {
    {
      threadPoolExecutor.getQueue();
      result = queue;
      queue.size();
      result = 10d;
    }
  };
  new MockUp<ScheduledThreadPoolExecutor>() {
    @Mock
    void delayedExecute(RunnableScheduledFuture<?> task) {

    }
  };
  try {
    ThreadPoolMonitor.attach(registry, threadPoolExecutor, "test");

    PolledMeter.update(registry);
    PublishModelFactory factory = new PublishModelFactory(Lists.newArrayList(registry.iterator()));
    DefaultPublishModel model = factory.createDefaultPublishModel();

    Assert.assertEquals(
        "{\"test\":{\"avgTaskCount\":0.0,\"avgCompletedTaskCount\":0.0,\"currentThreadsBusy\":0,\"maxThreads\":0,\"poolSize\":0,\"corePoolSize\":0,\"queueSize\":10,\"rejected\":\"NaN\"}}",
        JsonUtils.writeValueAsString(model.getThreadPools()));
  } catch (Throwable e) {
    e.printStackTrace();
    Assert.fail("unexpected error happen. " + e.getMessage());
  }
}
 
Example #25
Source File: LazyTraceScheduledThreadPoolExecutor.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
LazyTraceScheduledThreadPoolExecutor(int corePoolSize, ScheduledThreadPoolExecutor delegate) {
    super(corePoolSize);
    this.delegate = delegate;
    this.decorateTaskRunnable = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class, "decorateTask", Runnable.class,
            RunnableScheduledFuture.class);
    makeAccessibleIfNotNull(this.decorateTaskRunnable);
    this.decorateTaskCallable = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class, "decorateTaskCallable", Callable.class,
            RunnableScheduledFuture.class);
    makeAccessibleIfNotNull(this.decorateTaskCallable);
    this.finalize = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
            "finalize", null);
    makeAccessibleIfNotNull(this.finalize);
    this.beforeExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
            "beforeExecute", null);
    makeAccessibleIfNotNull(this.beforeExecute);
    this.afterExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
            "afterExecute", null);
    makeAccessibleIfNotNull(this.afterExecute);
    this.terminated = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
            "terminated", null);
    makeAccessibleIfNotNull(this.terminated);
    this.newTaskForRunnable = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class, "newTaskFor", Runnable.class,
            Object.class);
    makeAccessibleIfNotNull(this.newTaskForRunnable);
    this.newTaskForCallable = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class, "newTaskFor", Callable.class,
            Object.class);
    makeAccessibleIfNotNull(this.newTaskForCallable);
}
 
Example #26
Source File: MetricSafeScheduledExecutorService.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Override
protected <V> RunnableScheduledFuture<V> decorateTask(Runnable runnable, RunnableScheduledFuture<V> task) {
  return new MetricsTask<>(task);
}
 
Example #27
Source File: SchedulersTest.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
protected <V> RunnableScheduledFuture<V> decorateTask(
		Callable<V> c, RunnableScheduledFuture<V> task) {
	tasks.add(task);
	return task;
}
 
Example #28
Source File: OutOfBandScheduledExecutor.java    From ehcache3 with Apache License 2.0 4 votes vote down vote up
OutOfBandRsf(ExecutorService worker, RunnableScheduledFuture<T> original) {
  this.worker = worker;
  this.delegate = original;
}
 
Example #29
Source File: JitterScheduledThreadPoolExecutorImpl.java    From hbase with Apache License 2.0 4 votes vote down vote up
JitteredRunnableScheduledFuture(RunnableScheduledFuture<V> wrapped) {
  this.wrapped = wrapped;
}
 
Example #30
Source File: MetricSafeScheduledExecutorService.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Override
protected <V> RunnableScheduledFuture<V> decorateTask(Callable<V> callable, RunnableScheduledFuture<V> task) {
  return new MetricsTask<>(task);
}