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

下面列出了怎么用org.springframework.core.task.TaskDecorator的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: 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;
}
 
源代码2 项目: 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;
}
 
源代码3 项目: 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;
}
 
源代码4 项目: 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;
}
 
源代码5 项目: 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;
}
 
源代码6 项目: 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;
}
 
源代码7 项目: 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;
}
 
源代码8 项目: 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;
}
 
源代码9 项目: 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;
}
 
源代码10 项目: 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;
}
 
源代码11 项目: 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;
}
 
源代码12 项目: 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;
}
 
源代码13 项目: 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;
}
 
源代码14 项目: 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;
}
 
源代码15 项目: 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;
}
 
源代码16 项目: 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());
}
 
源代码17 项目: pinpoint   文件: ChainedTaskDecorator.java
@Override
public Runnable decorate(Runnable runnable) {
    Runnable decoratedRunnable = runnable;
    for (TaskDecorator taskDecorator : taskDecorators) {
        decoratedRunnable = taskDecorator.decorate(decoratedRunnable);
    }
    return decoratedRunnable;
}
 
源代码18 项目: cloudbreak   文件: CompositeTaskDecorator.java
@Override
public Runnable decorate(Runnable runnable) {
    Runnable decoratedRunnable = requireNonNull(runnable, "runnable is null");
    for (TaskDecorator decorator : decorators) {
        decoratedRunnable = decorator.decorate(decoratedRunnable);
    }
    return decoratedRunnable;
}
 
@Override
protected ExecutorService initializeExecutor(ThreadFactory threadFactory,
                                             RejectedExecutionHandler rejectedExecutionHandler) {
    Integer queueCapacity = ClassUtil.getField("queueCapacity", this);
    final TaskDecorator taskDecorator = ClassUtil.getField("taskDecorator", this);

    BlockingQueue<Runnable> queue = createQueue(queueCapacity);

    SofaThreadPoolExecutor executor;

    // When used as Spring bean, setter method is called before init method
    if (threadPoolName == null) {
        threadPoolName = createName();
    }

    if (taskDecorator != null) {
        executor = new SofaThreadPoolExecutor(getCorePoolSize(), getMaxPoolSize(),
            getKeepAliveSeconds(), TimeUnit.SECONDS, queue, threadFactory,
            rejectedExecutionHandler, threadPoolName, DEFAULT_TASK_TIMEOUT, DEFAULT_PERIOD,
            DEFAULT_TIME_UNIT) {
            @Override
            public void execute(Runnable command) {
                super.execute(taskDecorator.decorate(command));
            }
        };
    } else {
        executor = new SofaThreadPoolExecutor(getCorePoolSize(), getMaxPoolSize(),
            getKeepAliveSeconds(), TimeUnit.SECONDS, queue, threadFactory,
            rejectedExecutionHandler, threadPoolName, DEFAULT_TASK_TIMEOUT, DEFAULT_PERIOD,
            DEFAULT_TIME_UNIT);
    }

    Boolean allowCoreThreadTimeOut = ClassUtil.getField("allowCoreThreadTimeOut", this);
    if (allowCoreThreadTimeOut) {
        executor.allowCoreThreadTimeOut(true);
    }

    ClassUtil.setField("threadPoolExecutor", this, executor);
    this.sofaThreadPoolExecutor = executor;
    return executor;
}
 
@Override
public void setTaskDecorator(TaskDecorator taskDecorator) {
  this.delegate.setTaskDecorator(taskDecorator);
}
 
@Override
public void setTaskDecorator(TaskDecorator taskDecorator) {
	this.delegate.setTaskDecorator(taskDecorator);
}
 
源代码22 项目: pinpoint   文件: ChainedTaskDecorator.java
public ChainedTaskDecorator(List<TaskDecorator> taskDecorators) {
    this.taskDecorators = Objects.requireNonNull(taskDecorators, "taskDecorators");
}
 
@Override
public void setTaskDecorator(TaskDecorator taskDecorator) {
    this.delegate.setTaskDecorator(taskDecorator);
}
 
/**
 * 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;
}
 
/**
 * 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);
}
 
源代码26 项目: spring-analysis-note   文件: 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;
}
 
源代码27 项目: spring-analysis-note   文件: 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, @Nullable TaskDecorator taskDecorator, Runnable runnable)
		throws RejectedExecutionException{

	concurrentExecutor.execute(taskDecorator != null ? taskDecorator.decorate(runnable) : runnable);
}
 
/**
 * 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;
}
 
/**
 * 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;
}
 
/**
 * 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;
}
 
 类所在包
 类方法
 同包方法