Java 类org.springframework.core.task.TaskDecorator 实例源码

项目:Spring-5.0-Cookbook    文件:SpringAsynchConfig.java   
@Bean("mvcTaskexecutor")
    @Override
       public Executor getAsyncExecutor() {
        ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(
                   Executors.newFixedThreadPool(100));

        executor.setTaskDecorator(new TaskDecorator() {
             @Override
             public Runnable decorate (Runnable runnable) {
                 return () -> {

                     long t = System.currentTimeMillis();
                     runnable.run();
                     System.out.printf("Thread %s has a processing time:  %s%n", Thread.currentThread().getName(),       
                                       (System.currentTimeMillis() - t));
                 };
             }
         });
        return executor;
}
项目:Spring-5.0-Cookbook    文件:SpringAsynchConfig.java   
@Bean("mvcTaskexecutor")
    @Override
       public Executor getAsyncExecutor() {
        ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(
                   Executors.newFixedThreadPool(100));

        executor.setTaskDecorator(new TaskDecorator() {
             @Override
             public Runnable decorate (Runnable runnable) {
                 return () -> {

                     long t = System.currentTimeMillis();
                     runnable.run();
                     logger.info("creating ConcurrentTaskExecutor thread pool....");
                     System.out.printf("Thread %s has a processing time:  %s%n", Thread.currentThread().getName(),       
                                       (System.currentTimeMillis() - t));
                 };
             }
         });
        return executor;
}
项目:Spring-5.0-Cookbook    文件:SpringAsynchConfig.java   
@Bean("mvcTaskexecutor")
    @Override
       public Executor getAsyncExecutor() {
        ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(
                   Executors.newFixedThreadPool(100));

        executor.setTaskDecorator(new TaskDecorator() {
             @Override
             public Runnable decorate (Runnable runnable) {
                 return () -> {

                     long t = System.currentTimeMillis();
                     runnable.run();
                     logger.info("creating ConcurrentTaskExecutor thread pool....");
                     System.out.printf("Thread %s has a processing time:  %s%n", Thread.currentThread().getName(),       
                                       (System.currentTimeMillis() - t));
                 };
             }
         });
        return executor;
}
项目:Spring-5.0-Cookbook    文件:SpringAsynchConfig.java   
@Bean("mvcTaskexecutor")
    @Override
       public Executor getAsyncExecutor() {
        ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(
                   Executors.newFixedThreadPool(100));

        executor.setTaskDecorator(new TaskDecorator() {
             @Override
             public Runnable decorate (Runnable runnable) {
                 return () -> {

                     long t = System.currentTimeMillis();
                     runnable.run();
                     logger.info("creating ConcurrentTaskExecutor thread pool....");
                     System.out.printf("Thread %s has a processing time:  %s%n", Thread.currentThread().getName(),       
                                       (System.currentTimeMillis() - t));
                 };
             }
         });
        return executor;
}
项目:Spring-5.0-Cookbook    文件:SpringAsynchConfig.java   
@Bean("mvcTaskexecutor")
    @Override
       public Executor getAsyncExecutor() {
        ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(
                   Executors.newFixedThreadPool(100));

        executor.setTaskDecorator(new TaskDecorator() {
             @Override
             public Runnable decorate (Runnable runnable) {
                 return () -> {

                     long t = System.currentTimeMillis();
                     runnable.run();
                     logger.info("creating ConcurrentTaskExecutor thread pool....");
                     System.out.printf("Thread %s has a processing time:  %s%n", Thread.currentThread().getName(),       
                                       (System.currentTimeMillis() - t));
                 };
             }
         });
        return executor;
}
项目:Spring-5.0-Cookbook    文件:SpringAsynchConfig.java   
@Bean("mvcTaskexecutor")
    @Override
       public Executor getAsyncExecutor() {
        ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(
                   Executors.newFixedThreadPool(100));

        executor.setTaskDecorator(new TaskDecorator() {
             @Override
             public Runnable decorate (Runnable runnable) {
                 return () -> {

                     long t = System.currentTimeMillis();
                     runnable.run();
                     logger.info("creating ConcurrentTaskExecutor thread pool....");
                     System.out.printf("Thread %s has a processing time:  %s%n", Thread.currentThread().getName(),       
                                       (System.currentTimeMillis() - t));
                 };
             }
         });
        return executor;
}
项目:Spring-5.0-Cookbook    文件:SpringAsynchConfig.java   
@Bean("mvcTaskexecutor")
    @Override
       public Executor getAsyncExecutor() {
        ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(
                   Executors.newFixedThreadPool(100));

        executor.setTaskDecorator(new TaskDecorator() {
             @Override
             public Runnable decorate (Runnable runnable) {
                 return () -> {

                     long t = System.currentTimeMillis();
                     runnable.run();
                     logger.info("creating ConcurrentTaskExecutor thread pool....");
                     System.out.printf("Thread %s has a processing time:  %s%n", Thread.currentThread().getName(),       
                                       (System.currentTimeMillis() - t));
                 };
             }
         });
        return executor;
}
项目:Spring-5.0-Cookbook    文件:SpringAsynchConfig.java   
@Bean("mvcTaskexecutor")
    @Override
       public Executor getAsyncExecutor() {
        ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(
                   Executors.newFixedThreadPool(100));

        executor.setTaskDecorator(new TaskDecorator() {
             @Override
             public Runnable decorate (Runnable runnable) {
                 return () -> {

                     long t = System.currentTimeMillis();
                     runnable.run();
                     logger.info("creating ConcurrentTaskExecutor thread pool....");
                     System.out.printf("Thread %s has a processing time:  %s%n", Thread.currentThread().getName(),       
                                       (System.currentTimeMillis() - t));
                 };
             }
         });
        return executor;
}
项目:Spring-5.0-Cookbook    文件:SpringAsynchConfig.java   
@Bean("mvcTaskexecutor")
    @Override
       public Executor getAsyncExecutor() {
        ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(
                   Executors.newFixedThreadPool(100));

        executor.setTaskDecorator(new TaskDecorator() {
             @Override
             public Runnable decorate (Runnable runnable) {
                 return () -> {

                     long t = System.currentTimeMillis();
                     runnable.run();
                     logger.info("creating ConcurrentTaskExecutor thread pool....");
                     System.out.printf("Thread %s has a processing time:  %s%n", Thread.currentThread().getName(),       
                                       (System.currentTimeMillis() - t));
                 };
             }
         });
        return executor;
}
项目:Spring-5.0-Cookbook    文件:SpringAsynchConfig.java   
@Bean("mvcTaskexecutor")
    @Override
       public Executor getAsyncExecutor() {
        ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(
                   Executors.newFixedThreadPool(100));

        executor.setTaskDecorator(new TaskDecorator() {
             @Override
             public Runnable decorate (Runnable runnable) {
                 return () -> {

                     long t = System.currentTimeMillis();
                     runnable.run();
                     logger.info("creating ConcurrentTaskExecutor thread pool....");
                     System.out.printf("Thread %s has a processing time:  %s%n", Thread.currentThread().getName(),       
                                       (System.currentTimeMillis() - t));
                 };
             }
         });
        return executor;
}
项目:Spring-5.0-Cookbook    文件:SpringAsynchConfig.java   
@Bean("mvcTaskexecutor")
    @Override
       public Executor getAsyncExecutor() {
        ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(
                   Executors.newFixedThreadPool(100));

        executor.setTaskDecorator(new TaskDecorator() {
             @Override
             public Runnable decorate (Runnable runnable) {
                 return () -> {

                     long t = System.currentTimeMillis();
                     runnable.run();
                     logger.info("creating ConcurrentTaskExecutor thread pool....");
                     System.out.printf("Thread %s has a processing time:  %s%n", Thread.currentThread().getName(),       
                                       (System.currentTimeMillis() - t));
                 };
             }
         });
        return executor;
}
项目:Spring-5.0-Cookbook    文件:BatchConfig.java   
@Bean("mvcTaskexecutor")
  public TaskExecutor getAsyncExecutor() {
        ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(
                 Executors.newFixedThreadPool(100));

        executor.setTaskDecorator(new TaskDecorator() {
           @Override
           public Runnable decorate (Runnable runnable) {
               return () -> {

                   long t = System.currentTimeMillis();
                   runnable.run();
                   System.out.printf("Thread %s has a processing time:  %s%n", Thread.currentThread().getName(),       
                                     (System.currentTimeMillis() - t));
               };
           }
       });
        return executor;
}
项目:Spring-5.0-Cookbook    文件:SpringAsynchConfig.java   
@Bean("mvcTaskexecutor")
    @Override
       public Executor getAsyncExecutor() {
        ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(
                   Executors.newFixedThreadPool(100));

        executor.setTaskDecorator(new TaskDecorator() {
             @Override
             public Runnable decorate (Runnable runnable) {
                 return () -> {

                     long t = System.currentTimeMillis();
                     runnable.run();
                     logger.info("creating ConcurrentTaskExecutor thread pool....");
                     System.out.printf("Thread %s has a processing time:  %s%n", Thread.currentThread().getName(),       
                                       (System.currentTimeMillis() - t));
                 };
             }
         });
        return executor;
}
项目:pinpoint    文件:ChainedTaskDecoratorTest.java   
@Test
public void chainedDecoratorsShouldBeCalled() throws InterruptedException {
    // Given
    final int testCount = 100;
    final CountDownLatch completeLatch = new CountDownLatch(testCount);
    final CountingTaskDecorator decorator1 = new CountingTaskDecorator();
    final CountingTaskDecorator decorator2 = new CountingTaskDecorator();
    final CountingTaskDecorator decorator3 = new CountingTaskDecorator();
    final List<TaskDecorator> decorators = Arrays.asList(decorator1, decorator2, decorator3);
    final ChainedTaskDecorator chainedDecorator = new ChainedTaskDecorator(decorators);
    executor.setTaskDecorator(chainedDecorator);
    // When
    for (int i = 0; i < testCount; i++) {
        executor.execute(new TestWorker(completeLatch));
    }
    completeLatch.await(5L, TimeUnit.SECONDS);
    // Then
    Assert.assertEquals(testCount, decorator1.getCount());
    Assert.assertEquals(testCount, decorator2.getCount());
    Assert.assertEquals(testCount, decorator3.getCount());
}
项目:Spring-5.0-Cookbook    文件:SpringAsynchConfig.java   
@Bean("mvcTaskexecutor")
    @Override
       public Executor getAsyncExecutor() {
        ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(
                   Executors.newFixedThreadPool(100));

        executor.setTaskDecorator(new TaskDecorator() {
             @Override
             public Runnable decorate (Runnable runnable) {
                 return () -> {

                     long t = System.currentTimeMillis();
                     runnable.run();
                     logger.info("creating ConcurrentTaskExecutor thread pool....");
                     System.out.printf("Thread %s has a processing time:  %s%n", Thread.currentThread().getName(),       
                                       (System.currentTimeMillis() - t));
                 };
             }
         });
        return executor;
}
项目:Spring-5.0-Cookbook    文件:SpringAsynchConfig.java   
@Bean("mvcTaskexecutor")
    @Override
       public Executor getAsyncExecutor() {
        ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(
                   Executors.newFixedThreadPool(100));

        executor.setTaskDecorator(new TaskDecorator() {
             @Override
             public Runnable decorate (Runnable runnable) {
                 return () -> {

                     long t = System.currentTimeMillis();
                     runnable.run();
                     logger.info("creating ConcurrentTaskExecutor thread pool....");
                     System.out.printf("Thread %s has a processing time:  %s%n", Thread.currentThread().getName(),       
                                       (System.currentTimeMillis() - t));
                 };
             }
         });
        return executor;
}
项目:pinpoint    文件:ChainedTaskDecorator.java   
@Override
public Runnable decorate(Runnable runnable) {
    Runnable decoratedRunnable = runnable;
    for (TaskDecorator taskDecorator : taskDecorators) {
        decoratedRunnable = taskDecorator.decorate(decoratedRunnable);
    }
    return decoratedRunnable;
}
项目:spring-cloud-sleuth    文件:LazyTraceThreadPoolTaskExecutor.java   
@Override public void setTaskDecorator(TaskDecorator taskDecorator) {
    this.delegate.setTaskDecorator(taskDecorator);
}
项目:pinpoint    文件:ChainedTaskDecorator.java   
public ChainedTaskDecorator(List<TaskDecorator> taskDecorators) {
    this.taskDecorators = Objects.requireNonNull(taskDecorators, "taskDecorators must not be null");
}
项目:spring    文件:ThreadPoolTaskExecutor.java   
/**
 * Specify a custom {@link TaskDecorator} to be applied to any {@link Runnable}
 * about to be executed.
 * <p>Note that such a decorator is not necessarily being applied to the
 * user-supplied {@code Runnable}/{@code Callable} but rather to the actual
 * execution callback (which may be a wrapper around the user-supplied task).
 * <p>The primary use case is to set some execution context around the task's
 * invocation, or to provide some monitoring/statistics for task execution.
 * @since 4.3
 */
public void setTaskDecorator(TaskDecorator taskDecorator) {
    this.taskDecorator = taskDecorator;
}
项目:spring    文件:ConcurrentTaskExecutor.java   
/**
 * Specify a custom {@link TaskDecorator} to be applied to any {@link Runnable}
 * about to be executed.
 * <p>Note that such a decorator is not necessarily being applied to the
 * user-supplied {@code Runnable}/{@code Callable} but rather to the actual
 * execution callback (which may be a wrapper around the user-supplied task).
 * <p>The primary use case is to set some execution context around the task's
 * invocation, or to provide some monitoring/statistics for task execution.
 * @since 4.3
 */
public final void setTaskDecorator(TaskDecorator taskDecorator) {
    this.adaptedExecutor.setTaskDecorator(taskDecorator);
}
项目:spring    文件:TaskExecutorAdapter.java   
/**
 * Specify a custom {@link TaskDecorator} to be applied to any {@link Runnable}
 * about to be executed.
 * <p>Note that such a decorator is not necessarily being applied to the
 * user-supplied {@code Runnable}/{@code Callable} but rather to the actual
 * execution callback (which may be a wrapper around the user-supplied task).
 * <p>The primary use case is to set some execution context around the task's
 * invocation, or to provide some monitoring/statistics for task execution.
 * @since 4.3
 */
public final void setTaskDecorator(TaskDecorator taskDecorator) {
    this.taskDecorator = taskDecorator;
}
项目:spring    文件:TaskExecutorAdapter.java   
/**
 * Actually execute the given {@code Runnable} (which may be a user-supplied task
 * or a wrapper around a user-supplied task) with the given executor.
 * @param concurrentExecutor the underlying JDK concurrent executor to delegate to
 * @param taskDecorator the specified decorator to be applied, if any
 * @param runnable the runnable to execute
 * @throws RejectedExecutionException if the given runnable cannot be accepted
 * @since 4.3
 */
protected void doExecute(Executor concurrentExecutor, TaskDecorator taskDecorator, Runnable runnable)
        throws RejectedExecutionException{

    concurrentExecutor.execute(taskDecorator != null ? taskDecorator.decorate(runnable) : runnable);
}