配置
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
@Configuration
@EnableAsync
public class AppConfiguration implements AsyncConfigurer {
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(5);
executor.setMaxPoolSize(10);
executor.setQueueCapacity(25);
executor.setThreadNamePrefix("Async-");
executor.initialize();
return executor;
}
}
接口
public interface IAsyncService {
void smsPush(SmsPushRO ro);
void emailPush(EmailPushRO ro);
}
接口实现
@Service
@Slf4j
public class AsyncServiceImpl implements IAsyncService {
@Async
@Override
public void smsPush(SmsPushRO ro) {
}
@Async
@Override
public void emailPush(EmailPushRO ro) {
}
}