Skip to content

Commit 535d87c

Browse files
committed
separate TaskExecutor and TaskScheduler usage
1 parent 5434ac7 commit 535d87c

File tree

8 files changed

+129
-16
lines changed

8 files changed

+129
-16
lines changed

src/main/java/de/rwth/idsg/steve/config/BeanConfiguration.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.springframework.http.converter.HttpMessageConverter;
4545
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
4646
import org.springframework.scheduling.annotation.EnableScheduling;
47+
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
4748
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
4849
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
4950
import org.springframework.web.accept.ContentNegotiationManager;
@@ -59,7 +60,6 @@
5960

6061
import javax.sql.DataSource;
6162
import java.util.List;
62-
import java.util.concurrent.Executor;
6363

6464
import static de.rwth.idsg.steve.SteveConfiguration.CONFIG;
6565

@@ -137,15 +137,28 @@ public DSLContext dslContext(DataSource dataSource) {
137137
return DSL.using(conf);
138138
}
139139

140-
@Bean(name = {"asyncTaskScheduler", "asyncTaskExecutor"})
141-
public ThreadPoolTaskScheduler asyncTaskScheduler() {
140+
@Bean(destroyMethod = "close")
141+
public DelegatingTaskScheduler asyncTaskScheduler() {
142142
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
143143
scheduler.setPoolSize(5);
144-
scheduler.setThreadNamePrefix("SteVe-Executor-");
144+
scheduler.setThreadNamePrefix("SteVe-TaskScheduler-");
145145
scheduler.setWaitForTasksToCompleteOnShutdown(true);
146146
scheduler.setAwaitTerminationSeconds(30);
147147
scheduler.initialize();
148-
return scheduler;
148+
149+
return new DelegatingTaskScheduler(scheduler);
150+
}
151+
152+
@Bean(destroyMethod = "close")
153+
public DelegatingTaskExecutor asyncTaskExecutor() {
154+
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
155+
executor.setCorePoolSize(5);
156+
executor.setThreadNamePrefix("SteVe-TaskExecutor-");
157+
executor.setWaitForTasksToCompleteOnShutdown(true);
158+
executor.setAwaitTerminationSeconds(30);
159+
executor.initialize();
160+
161+
return new DelegatingTaskExecutor(executor);
149162
}
150163

151164
@Bean
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* SteVe - SteckdosenVerwaltung - https://github.com/steve-community/steve
3+
* Copyright (C) 2013-2025 SteVe Community Team
4+
* All Rights Reserved.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
package de.rwth.idsg.steve.config;
20+
21+
import lombok.RequiredArgsConstructor;
22+
import lombok.extern.slf4j.Slf4j;
23+
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
24+
25+
import java.io.Closeable;
26+
import java.io.IOException;
27+
28+
/**
29+
* @author Sevket Goekay <[email protected]>
30+
* @since 02.02.2025
31+
*/
32+
@Slf4j
33+
@RequiredArgsConstructor
34+
public class DelegatingTaskExecutor implements Closeable {
35+
36+
private final ThreadPoolTaskExecutor delegate;
37+
38+
@Override
39+
public void close() throws IOException {
40+
log.info("Shutting down");
41+
delegate.shutdown();
42+
}
43+
44+
public void execute(Runnable task) {
45+
delegate.execute(task);
46+
}
47+
48+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* SteVe - SteckdosenVerwaltung - https://github.com/steve-community/steve
3+
* Copyright (C) 2013-2025 SteVe Community Team
4+
* All Rights Reserved.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
package de.rwth.idsg.steve.config;
20+
21+
import lombok.RequiredArgsConstructor;
22+
import lombok.extern.slf4j.Slf4j;
23+
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
24+
25+
import java.io.Closeable;
26+
import java.io.IOException;
27+
import java.time.Duration;
28+
import java.time.Instant;
29+
import java.util.concurrent.ScheduledFuture;
30+
31+
/**
32+
* @author Sevket Goekay <[email protected]>
33+
* @since 02.02.2025
34+
*/
35+
@Slf4j
36+
@RequiredArgsConstructor
37+
public class DelegatingTaskScheduler implements Closeable {
38+
39+
private final ThreadPoolTaskScheduler delegate;
40+
41+
@Override
42+
public void close() throws IOException {
43+
log.info("Shutting down");
44+
delegate.shutdown();
45+
}
46+
47+
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Instant startTime, Duration period) {
48+
return delegate.scheduleAtFixedRate(task, startTime, period);
49+
}
50+
51+
}

src/main/java/de/rwth/idsg/steve/ocpp/soap/MessageHeaderInterceptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package de.rwth.idsg.steve.ocpp.soap;
2020

21+
import de.rwth.idsg.steve.config.DelegatingTaskExecutor;
2122
import de.rwth.idsg.steve.ocpp.OcppProtocol;
2223
import de.rwth.idsg.steve.repository.OcppServerRepository;
2324
import de.rwth.idsg.steve.repository.impl.ChargePointRepositoryImpl;
@@ -41,7 +42,6 @@
4142

4243
import javax.xml.namespace.QName;
4344
import java.util.Optional;
44-
import java.util.concurrent.Executor;
4545

4646
import static org.apache.cxf.ws.addressing.JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND;
4747

@@ -62,7 +62,7 @@ public class MessageHeaderInterceptor extends AbstractPhaseInterceptor<Message>
6262

6363
@Autowired private OcppServerRepository ocppServerRepository;
6464
@Autowired private ChargePointHelperService chargePointHelperService;
65-
@Autowired private Executor asyncTaskExecutor;
65+
@Autowired private DelegatingTaskExecutor asyncTaskExecutor;
6666

6767
private static final String BOOT_OPERATION_NAME = "BootNotification";
6868
private static final String CHARGEBOX_ID_HEADER = "ChargeBoxIdentity";

src/main/java/de/rwth/idsg/steve/ocpp/ws/AbstractWebSocketEndpoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.google.common.base.Strings;
2222
import de.rwth.idsg.steve.config.WebSocketConfiguration;
23+
import de.rwth.idsg.steve.config.DelegatingTaskScheduler;
2324
import de.rwth.idsg.steve.ocpp.OcppTransport;
2425
import de.rwth.idsg.steve.ocpp.OcppVersion;
2526
import de.rwth.idsg.steve.ocpp.ws.data.CommunicationContext;
@@ -31,7 +32,6 @@
3132
import org.joda.time.DateTime;
3233
import org.springframework.beans.factory.annotation.Autowired;
3334
import org.springframework.context.ApplicationEventPublisher;
34-
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
3535
import org.springframework.web.socket.BinaryMessage;
3636
import org.springframework.web.socket.CloseStatus;
3737
import org.springframework.web.socket.PongMessage;
@@ -55,7 +55,7 @@
5555
*/
5656
public abstract class AbstractWebSocketEndpoint extends ConcurrentWebSocketHandler implements SubProtocolCapable {
5757

58-
@Autowired private ThreadPoolTaskScheduler asyncTaskScheduler;
58+
@Autowired private DelegatingTaskScheduler asyncTaskScheduler;
5959
@Autowired private OcppServerRepository ocppServerRepository;
6060
@Autowired private FutureResponseContextStore futureResponseContextStore;
6161
@Autowired private ApplicationEventPublisher applicationEventPublisher;

src/main/java/de/rwth/idsg/steve/service/BackgroundService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
*/
1919
package de.rwth.idsg.steve.service;
2020

21+
import de.rwth.idsg.steve.config.DelegatingTaskExecutor;
2122
import de.rwth.idsg.steve.repository.dto.ChargePointSelect;
2223
import lombok.AccessLevel;
2324
import lombok.RequiredArgsConstructor;
2425

2526
import java.util.List;
26-
import java.util.concurrent.Executor;
2727
import java.util.function.Consumer;
2828

2929
/**
@@ -32,9 +32,10 @@
3232
*/
3333
@RequiredArgsConstructor
3434
public class BackgroundService {
35-
private final Executor asyncTaskExecutor;
3635

37-
public static BackgroundService with(Executor asyncTaskExecutor) {
36+
private final DelegatingTaskExecutor asyncTaskExecutor;
37+
38+
public static BackgroundService with(DelegatingTaskExecutor asyncTaskExecutor) {
3839
return new BackgroundService(asyncTaskExecutor);
3940
}
4041

src/main/java/de/rwth/idsg/steve/service/ChargePointServiceClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package de.rwth.idsg.steve.service;
2020

2121
import de.rwth.idsg.steve.SteveException;
22+
import de.rwth.idsg.steve.config.DelegatingTaskExecutor;
2223
import de.rwth.idsg.steve.ocpp.ChargePointServiceInvokerImpl;
2324
import de.rwth.idsg.steve.ocpp.OcppCallback;
2425
import de.rwth.idsg.steve.ocpp.task.CancelReservationTask;
@@ -74,7 +75,6 @@
7475
import org.springframework.stereotype.Service;
7576

7677
import java.util.List;
77-
import java.util.concurrent.Executor;
7878

7979
/**
8080
* @author Sevket Goekay <[email protected]>
@@ -89,7 +89,7 @@ public class ChargePointServiceClient {
8989
private final ReservationRepository reservationRepository;
9090
private final OcppTagService ocppTagService;
9191

92-
private final Executor asyncTaskExecutor;
92+
private final DelegatingTaskExecutor asyncTaskExecutor;
9393
private final TaskStore taskStore;
9494
private final ChargePointServiceInvokerImpl invoker;
9595

src/main/java/de/rwth/idsg/steve/service/MailService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.google.common.base.Strings;
2222
import de.rwth.idsg.steve.SteveException;
23+
import de.rwth.idsg.steve.config.DelegatingTaskExecutor;
2324
import de.rwth.idsg.steve.repository.SettingsRepository;
2425
import de.rwth.idsg.steve.repository.dto.MailSettings;
2526
import lombok.extern.slf4j.Slf4j;
@@ -36,7 +37,6 @@
3637
import jakarta.mail.internet.MimeMessage;
3738

3839
import java.util.Properties;
39-
import java.util.concurrent.Executor;
4040

4141
/**
4242
* @author Sevket Goekay <[email protected]>
@@ -47,7 +47,7 @@
4747
public class MailService {
4848

4949
@Autowired private SettingsRepository settingsRepository;
50-
@Autowired private Executor asyncTaskExecutor;
50+
@Autowired private DelegatingTaskExecutor asyncTaskExecutor;
5151

5252
public MailSettings getSettings() {
5353
return settingsRepository.getMailSettings();

0 commit comments

Comments
 (0)