本文整理汇总了Java中org.springframework.core.task.TaskDecorator类的典型用法代码示例。如果您正苦于以下问题:Java TaskDecorator类的具体用法?Java TaskDecorator怎么用?Java TaskDecorator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TaskDecorator类属于org.springframework.core.task包,在下文中一共展示了TaskDecorator类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getAsyncExecutor
点赞 3
import org.springframework.core.task.TaskDecorator; //导入依赖的package包/类
@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;
}
开发者ID:PacktPublishing,
项目名称:Spring-5.0-Cookbook,
代码行数:21,
代码来源:SpringAsynchConfig.java
示例2: getAsyncExecutor
点赞 3
import org.springframework.core.task.TaskDecorator; //导入依赖的package包/类
@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;
}
开发者ID:PacktPublishing,
项目名称:Spring-5.0-Cookbook,
代码行数:22,
代码来源:SpringAsynchConfig.java
示例3: getAsyncExecutor
点赞 3
import org.springframework.core.task.TaskDecorator; //导入依赖的package包/类
@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;
}
开发者ID:PacktPublishing,
项目名称:Spring-5.0-Cookbook,
代码行数:20,
代码来源:BatchConfig.java
示例4: chainedDecoratorsShouldBeCalled
点赞 3
import org.springframework.core.task.TaskDecorator; //导入依赖的package包/类
@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());
}
开发者ID:naver,
项目名称:pinpoint,
代码行数:22,
代码来源:ChainedTaskDecoratorTest.java
示例5: decorate
点赞 2
import org.springframework.core.task.TaskDecorator; //导入依赖的package包/类
@Override
public Runnable decorate(Runnable runnable) {
Runnable decoratedRunnable = runnable;
for (TaskDecorator taskDecorator : taskDecorators) {
decoratedRunnable = taskDecorator.decorate(decoratedRunnable);
}
return decoratedRunnable;
}
开发者ID:naver,
项目名称:pinpoint,
代码行数:9,
代码来源:ChainedTaskDecorator.java
示例6: setTaskDecorator
点赞 2
import org.springframework.core.task.TaskDecorator; //导入依赖的package包/类
@Override public void setTaskDecorator(TaskDecorator taskDecorator) {
this.delegate.setTaskDecorator(taskDecorator);
}
开发者ID:spring-cloud,
项目名称:spring-cloud-sleuth,
代码行数:4,
代码来源:LazyTraceThreadPoolTaskExecutor.java
示例7: ChainedTaskDecorator
点赞 2
import org.springframework.core.task.TaskDecorator; //导入依赖的package包/类
public ChainedTaskDecorator(List<TaskDecorator> taskDecorators) {
this.taskDecorators = Objects.requireNonNull(taskDecorators, "taskDecorators must not be null");
}
开发者ID:naver,
项目名称:pinpoint,
代码行数:4,
代码来源:ChainedTaskDecorator.java
示例8: setTaskDecorator
点赞 1
import org.springframework.core.task.TaskDecorator; //导入依赖的package包/类
/**
* 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;
}
开发者ID:txazo,
项目名称:spring,
代码行数:14,
代码来源:ThreadPoolTaskExecutor.java
示例9: setTaskDecorator
点赞 1
import org.springframework.core.task.TaskDecorator; //导入依赖的package包/类
/**
* 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);
}
开发者ID:txazo,
项目名称:spring,
代码行数:14,
代码来源:ConcurrentTaskExecutor.java
示例10: setTaskDecorator
点赞 1
import org.springframework.core.task.TaskDecorator; //导入依赖的package包/类
/**
* 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;
}
开发者ID:txazo,
项目名称:spring,
代码行数:14,
代码来源:TaskExecutorAdapter.java
示例11: doExecute
点赞 1
import org.springframework.core.task.TaskDecorator; //导入依赖的package包/类
/**
* 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);
}
开发者ID:txazo,
项目名称:spring,
代码行数:15,
代码来源:TaskExecutorAdapter.java