forked from mtusi2026/mtusi2026lab2
concurrency
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package ru.mtusi.messenger.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Configuration
|
||||
public class ExecutorConfig {
|
||||
|
||||
@Bean(destroyMethod = "shutdown")
|
||||
public ExecutorService cacheEvictExecutor() {
|
||||
AtomicInteger counter = new AtomicInteger();
|
||||
ThreadFactory factory = r -> {
|
||||
Thread t = new Thread(r, "cache-evict-" + counter.incrementAndGet());
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
};
|
||||
return Executors.newSingleThreadExecutor(factory);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user