Spring Bootでコンカレンシーを設定するステップは?
Spring Bootのコンカレンシーは、下記の手順で設定できます:
- pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
- application.properties
- application.yml
# application.properties
spring.task.execution.pool.core-size=10
spring.task.execution.pool.max-size=20
spring.task.execution.pool.queue-capacity=100
# application.yml
spring:
task:
execution:
pool:
core-size: 10
max-size: 20
queue-capacity: 100
- 非同期で
- 非同期の
@Service
public class MyService {
@Async
public CompletableFuture<String> asyncMethod() {
// 执行异步任务
return CompletableFuture.completedFuture("Done");
}
}
- 非同期を有効にする
@SpringBootApplication
@EnableAsync
public class Application {
// ...
}
以上の手順に従うことで、Spring Bootの非同期機能を設定および使用できるようになります。