Skip to content

Commit ebcf6c8

Browse files
author
eugenp
committed
work on a cleanup bean
1 parent 0b42f56 commit ebcf6c8

4 files changed

Lines changed: 76 additions & 6 deletions

File tree

‎spring-all/pom.xml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
<name>spring-all</name>
88
<packaging>war</packaging>
99

10+
<parent>
11+
<groupId>org.springframework.boot</groupId>
12+
<artifactId>spring-boot-starter-parent</artifactId>
13+
<version>1.2.5.RELEASE</version>
14+
</parent>
15+
1016
<dependencies>
1117

1218
<!-- Spring -->
@@ -101,6 +107,27 @@
101107
<artifactId>guava</artifactId>
102108
<version>${guava.version}</version>
103109
</dependency>
110+
111+
<!-- logging -->
112+
113+
<dependency>
114+
<groupId>org.slf4j</groupId>
115+
<artifactId>slf4j-api</artifactId>
116+
</dependency>
117+
<dependency>
118+
<groupId>ch.qos.logback</groupId>
119+
<artifactId>logback-classic</artifactId>
120+
<!-- <scope>runtime</scope> -->
121+
</dependency>
122+
<dependency>
123+
<groupId>org.slf4j</groupId>
124+
<artifactId>jcl-over-slf4j</artifactId>
125+
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
126+
</dependency>
127+
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
128+
<groupId>org.slf4j</groupId>
129+
<artifactId>log4j-over-slf4j</artifactId>
130+
</dependency>
104131

105132
<!-- test scoped -->
106133

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.baeldung.spring.config;
2+
3+
import java.util.concurrent.ExecutorService;
4+
5+
import org.springframework.beans.factory.DisposableBean;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.stereotype.Component;
8+
9+
@Component
10+
public final class CleanupBean implements DisposableBean {
11+
12+
@Autowired
13+
private ExecutorService setupExecutor;
14+
15+
public CleanupBean() {
16+
super();
17+
}
18+
19+
//
20+
21+
@Override
22+
public void destroy() {
23+
setupExecutor.shutdownNow();
24+
}
25+
26+
}

‎spring-all/src/main/java/org/baeldung/spring/config/CoreConfig.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package org.baeldung.spring.config;
22

3+
import java.util.concurrent.ExecutorService;
4+
import java.util.concurrent.LinkedBlockingQueue;
5+
import java.util.concurrent.ThreadPoolExecutor;
6+
import java.util.concurrent.TimeUnit;
7+
8+
import org.springframework.context.annotation.Bean;
39
import org.springframework.context.annotation.ComponentScan;
410
import org.springframework.context.annotation.Configuration;
511
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@@ -12,4 +18,15 @@ public CoreConfig() {
1218
super();
1319
}
1420

21+
// beans
22+
23+
@Bean
24+
public ExecutorService setupExecutor() {
25+
final int coreThreads = 4;
26+
final int maxThreads = 8;
27+
final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(coreThreads, maxThreads, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
28+
threadPoolExecutor.allowCoreThreadTimeOut(true);
29+
return threadPoolExecutor;
30+
}
31+
1532
}

‎spring-security-rest-full/pom.xml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
<name>spring-security-rest-full</name>
88
<packaging>war</packaging>
99

10+
<parent>
11+
<groupId>org.springframework.boot</groupId>
12+
<artifactId>spring-boot-starter-parent</artifactId>
13+
<version>1.2.5.RELEASE</version>
14+
</parent>
15+
1016
<dependencies>
1117

1218
<!-- Spring Boot Dependencies -->
@@ -454,10 +460,4 @@
454460

455461
</properties>
456462

457-
<parent>
458-
<groupId>org.springframework.boot</groupId>
459-
<artifactId>spring-boot-starter-parent</artifactId>
460-
<version>1.2.4.RELEASE</version>
461-
</parent>
462-
463463
</project>

0 commit comments

Comments
 (0)