Search in sources :

Example 86 with ThreadPoolTaskExecutor

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();
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 87 with ThreadPoolTaskExecutor

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;
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Bean(org.springframework.context.annotation.Bean)

Example 88 with ThreadPoolTaskExecutor

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();
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 89 with ThreadPoolTaskExecutor

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");
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Test(org.junit.Test)

Example 90 with ThreadPoolTaskExecutor

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;
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)

Aggregations

ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)152 Bean (org.springframework.context.annotation.Bean)72 ExceptionHandlingAsyncTaskExecutor (io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor)19 Test (org.junit.jupiter.api.Test)19 BigInteger (java.math.BigInteger)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 RateLimiter (com.google.common.util.concurrent.RateLimiter)14 Test (org.junit.Test)14 Random (java.util.Random)12 ApplicationContext (org.springframework.context.ApplicationContext)12 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)9 Service (org.fisco.bcos.channel.client.Service)9 Credentials (org.fisco.bcos.web3j.crypto.Credentials)9 Web3j (org.fisco.bcos.web3j.protocol.Web3j)9 ChannelEthereumService (org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)9 TransactionReceipt (org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt)9 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)6 MDCCleanerTaskDecorator (com.sequenceiq.cloudbreak.concurrent.MDCCleanerTaskDecorator)4