work on a cleanup bean
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package org.baeldung.spring.config;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public final class CleanupBean implements DisposableBean {
|
||||
|
||||
@Autowired
|
||||
private ExecutorService setupExecutor;
|
||||
|
||||
public CleanupBean() {
|
||||
super();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
setupExecutor.shutdownNow();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
package org.baeldung.spring.config;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
@@ -12,4 +18,15 @@ public class CoreConfig extends WebMvcConfigurerAdapter {
|
||||
super();
|
||||
}
|
||||
|
||||
// beans
|
||||
|
||||
@Bean
|
||||
public ExecutorService setupExecutor() {
|
||||
final int coreThreads = 4;
|
||||
final int maxThreads = 8;
|
||||
final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(coreThreads, maxThreads, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
|
||||
threadPoolExecutor.allowCoreThreadTimeOut(true);
|
||||
return threadPoolExecutor;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user