use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project neubbs by nuitcoder.
the class AccountControllerTest method testForgetPasswordSuccess.
/**
* 测试 /api/account/forget-password
* - 忘记密码成功
* - 重新设置临时密码,并发送邮件提示
* - 主线程等待,邮件线程发送完毕再继续执行
*/
@Test
@Transactional
public void testForgetPasswordSuccess() throws Exception {
String email = "liushuwei0925@gmail.com";
String requestBody = "{\"email\":\"" + email + "\"}";
System.out.println("input request-body:" + requestBody);
mockMvc.perform(MockMvcRequestBuilders.post("/api/account/forget-password").contentType(MediaType.APPLICATION_JSON).content(requestBody).accept(MediaType.APPLICATION_JSON)).andExpect(MockMvcResultMatchers.jsonPath("$.success").value(true)).andExpect(MockMvcResultMatchers.jsonPath("$.message").value("")).andExpect(MockMvcResultMatchers.jsonPath("$.model").exists());
// wait send mail thread send success
ThreadPoolTaskExecutor taskExecutor = (ThreadPoolTaskExecutor) webApplicationContext.getBean("taskExecutor");
int timer = 1;
while (taskExecutor.getActiveCount() > 0 && timer < 60) {
Thread.sleep(1000);
System.out.println("already wait " + (timer++) + "s");
}
System.out.println("send alter temporary password mail to '" + email + "' success!");
util.printSuccessMessage();
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project free-framework by a601942905git.
the class ExecutorConfig method myAsync.
@Bean
public Executor myAsync() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(CORE_POOL_SIZE);
executor.setMaxPoolSize(MAX_POOL_SIZE);
executor.setQueueCapacity(QUEEN_CAPACITY);
executor.setThreadNamePrefix("CustomerExecutor-");
// rejection-policy:当pool已经达到max size的时候,如何处理新任务
// CALLER_RUNS:不在新线程中执行任务,而是由调用者所在的线程来执行
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.initialize();
return executor;
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project micrometer by micrometer-metrics.
the class ThreadPoolTaskExecutorMetricsTest method executor.
@Test
public void executor() throws InterruptedException {
CountDownLatch lock = new CountDownLatch(1);
ThreadPoolTaskExecutor pool = ThreadPoolTaskExecutorMetrics.monitor(registry, "exec", userTags);
pool.setAwaitTerminationSeconds(1);
pool.initialize();
pool.execute(() -> {
System.out.println("hello");
lock.countDown();
});
lock.await();
pool.shutdown();
assertThat(registry.get("exec").tags(userTags).timer().count()).isEqualTo(1L);
registry.get("exec.completed").tags(userTags).functionCounter();
registry.get("exec.queued").tags(userTags).gauge();
registry.get("exec.active").tags(userTags).gauge();
registry.get("exec.pool").tags(userTags).gauge();
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project micrometer by micrometer-metrics.
the class ExecutorServiceMetricsTest method threadPoolTaskExecutor.
@Test
public void threadPoolTaskExecutor() {
ThreadPoolTaskExecutor exec = new ThreadPoolTaskExecutor();
exec.initialize();
ExecutorServiceMetrics.monitor(registry, exec.getThreadPoolExecutor(), "exec");
assertThreadPoolExecutorMetrics("exec");
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project SONG by overture-stack.
the class AsyncProcessingConfig method getAsyncExecutor.
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.setThreadNamePrefix("SongMessageValidation-");
executor.initialize();
return executor;
}
Aggregations