本文整理汇总了Java中org.springframework.scheduling.support.TaskUtils类的典型用法代码示例。如果您正苦于以下问题:Java TaskUtils类的具体用法?Java TaskUtils怎么用?Java TaskUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TaskUtils类属于org.springframework.scheduling.support包,在下文中一共展示了TaskUtils类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PdpController
import org.springframework.scheduling.support.TaskUtils; //导入依赖的package包/类
@Autowired
public PdpController(@Value("${period.policies.refresh.minutes}") int period,
@Value("${policies.cachePolicies}") boolean cachePolicies,
@Value("${loa.levels}") String loaLevelsCommaSeparated,
PdpPolicyViolationRepository pdpPolicyViolationRepository,
PdpPolicyRepository pdpPolicyRepository,
PDPEngineHolder pdpEngineHolder,
ServiceRegistry serviceRegistry,
MailBox mailBox,
PolicyMissingServiceProviderValidator policyMissingServiceProviderValidator) {
this.cachePolicies = cachePolicies;
this.loaLevels = Stream.of(loaLevelsCommaSeparated.split(",")).map(String::trim).collect(toList());
this.pdpEngineHolder = pdpEngineHolder;
this.playgroundPdpEngine = pdpEngineHolder.newPdpEngine(false, true);
this.pdpEngine = pdpEngineHolder.newPdpEngine(cachePolicies, false);
this.pdpPolicyViolationRepository = pdpPolicyViolationRepository;
this.policyIdpAccessEnforcer = new PolicyIdpAccessEnforcer(serviceRegistry);
this.pdpPolicyRepository = pdpPolicyRepository;
this.serviceRegistry = serviceRegistry;
this.mailBox = mailBox;
this.policyMissingServiceProviderValidator = policyMissingServiceProviderValidator;
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(
TaskUtils.decorateTaskWithErrorHandler(this::refreshPolicies, t -> LOG.error("Exception in refreshPolicies task", t), true),
period, period, TimeUnit.MINUTES);
}
示例2: schedule
import org.springframework.scheduling.support.TaskUtils; //导入依赖的package包/类
@Override
public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {
try {
if (this.enterpriseConcurrentScheduler) {
return new EnterpriseConcurrentTriggerScheduler().schedule(decorateTask(task, true), trigger);
}
else {
ErrorHandler errorHandler = (this.errorHandler != null ? this.errorHandler : TaskUtils.getDefaultErrorHandler(true));
return new ReschedulingRunnable(task, trigger, this.scheduledExecutor, errorHandler).schedule();
}
}
catch (RejectedExecutionException ex) {
throw new TaskRejectedException("Executor [" + this.scheduledExecutor + "] did not accept task: " + task, ex);
}
}
示例3: decorateTask
import org.springframework.scheduling.support.TaskUtils; //导入依赖的package包/类
private Runnable decorateTask(Runnable task, boolean isRepeatingTask) {
Runnable result = TaskUtils.decorateTaskWithErrorHandler(task, this.errorHandler, isRepeatingTask);
if (this.enterpriseConcurrentScheduler) {
result = ManagedTaskBuilder.buildManagedTask(result, task.toString());
}
return result;
}
示例4: schedule
import org.springframework.scheduling.support.TaskUtils; //导入依赖的package包/类
@Override
public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {
ScheduledExecutorService executor = getScheduledExecutor();
try {
ErrorHandler errorHandler =
(this.errorHandler != null ? this.errorHandler : TaskUtils.getDefaultErrorHandler(true));
return new ReschedulingRunnable(task, trigger, executor, errorHandler).schedule();
}
catch (RejectedExecutionException ex) {
throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
}
}
示例5: simpleApplicationEventMulticasterWithErrorHandler
import org.springframework.scheduling.support.TaskUtils; //导入依赖的package包/类
@Test
public void simpleApplicationEventMulticasterWithErrorHandler() {
@SuppressWarnings("unchecked")
ApplicationListener<ApplicationEvent> listener = mock(ApplicationListener.class);
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
smc.setErrorHandler(TaskUtils.LOG_AND_SUPPRESS_ERROR_HANDLER);
smc.addApplicationListener(listener);
willThrow(new RuntimeException()).given(listener).onApplicationEvent(evt);
smc.multicastEvent(evt);
}
示例6: schedule
import org.springframework.scheduling.support.TaskUtils; //导入依赖的package包/类
public ScheduledFuture schedule(Runnable task, Trigger trigger) {
try {
ErrorHandler errorHandler =
(this.errorHandler != null ? this.errorHandler : TaskUtils.getDefaultErrorHandler(true));
return new ReschedulingRunnable(task, trigger, this.scheduledExecutor, errorHandler).schedule();
}
catch (RejectedExecutionException ex) {
throw new TaskRejectedException("Executor [" + this.scheduledExecutor + "] did not accept task: " + task, ex);
}
}
示例7: schedule
import org.springframework.scheduling.support.TaskUtils; //导入依赖的package包/类
public ScheduledFuture schedule(Runnable task, Trigger trigger) {
ScheduledExecutorService executor = getScheduledExecutor();
try {
ErrorHandler errorHandler =
(this.errorHandler != null ? this.errorHandler : TaskUtils.getDefaultErrorHandler(true));
return new ReschedulingRunnable(task, trigger, executor, errorHandler).schedule();
}
catch (RejectedExecutionException ex) {
throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
}
}
示例8: start
import org.springframework.scheduling.support.TaskUtils; //导入依赖的package包/类
@PostConstruct
public void start() throws Exception {
Validate.isTrue(period > 0);
//任何异常不会中断schedule执行, 由Spring TaskUtils的LOG_AND_SUPPRESS_ERROR_HANDLER進行处理
Runnable task = TaskUtils.decorateTaskWithErrorHandler(this, null, true);
//创建单线程的SechdulerExecutor,并用guava的ThreadFactoryBuilder设定生成线程的名称
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat(
"JdkTimerJob-%1$d").build());
//scheduleAtFixedRatefixRate() 固定任务两次启动之间的时间间隔.
//scheduleAtFixedDelay() 固定任务结束后到下一次启动间的时间间隔.
scheduledExecutorService.scheduleAtFixedRate(task, initialDelay, period, TimeUnit.SECONDS);
}
示例9: errorHandlingTask
import org.springframework.scheduling.support.TaskUtils; //导入依赖的package包/类
private Runnable errorHandlingTask(Runnable task, boolean isRepeatingTask) {
return TaskUtils.decorateTaskWithErrorHandler(task, this.errorHandler, isRepeatingTask);
}
示例10: errorHandlingTask
import org.springframework.scheduling.support.TaskUtils; //导入依赖的package包/类
private Runnable errorHandlingTask(Runnable delegate, boolean isRepeatingTask) {
return TaskUtils.decorateTaskWithErrorHandler(delegate, this.errorHandler, isRepeatingTask);
}
示例11: getRunnableToSchedule
import org.springframework.scheduling.support.TaskUtils; //导入依赖的package包/类
/**
* Determine the actual Runnable to schedule for the given task.
* <p>Wraps the task's Runnable in a
* {@link org.springframework.scheduling.support.DelegatingErrorHandlingRunnable}
* that will catch and log the Exception. If necessary, it will suppress the
* Exception according to the
* {@link #setContinueScheduledExecutionAfterException "continueScheduledExecutionAfterException"}
* flag.
* @param task the ScheduledExecutorTask to schedule
* @return the actual Runnable to schedule (may be a decorator)
*/
protected Runnable getRunnableToSchedule(ScheduledExecutorTask task) {
return (this.continueScheduledExecutionAfterException ?
new DelegatingErrorHandlingRunnable(task.getRunnable(), TaskUtils.LOG_AND_SUPPRESS_ERROR_HANDLER) :
new DelegatingErrorHandlingRunnable(task.getRunnable(), TaskUtils.LOG_AND_PROPAGATE_ERROR_HANDLER));
}