work on a cleanup bean

This commit is contained in:
eugenp 2015-08-23 21:02:04 +03:00
parent 0b42f56f49
commit ebcf6c8b74
4 changed files with 76 additions and 6 deletions

View File

@ -7,6 +7,12 @@
<name>spring-all</name>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
</parent>
<dependencies>
<!-- Spring -->
@ -101,6 +107,27 @@
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<!-- <scope>runtime</scope> -->
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
</dependency>
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
<!-- test scoped -->

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -7,6 +7,12 @@
<name>spring-security-rest-full</name>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
</parent>
<dependencies>
<!-- Spring Boot Dependencies -->
@ -454,10 +460,4 @@
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.4.RELEASE</version>
</parent>
</project>