Skip to content

Commit 6ae2022

Browse files
Ali Ihsan TASDELENalihsan-tsdln
authored andcommitted
Refactor EurekaServerInitializerConfiguration
Replace the raw 'new Thread' creation with CompletableFuture.runAsync() to align with modern Java concurrency practices. Consolidate field injection and ServletContextAware into a single constructor. Add the volatile keyword to the 'running' flag to ensure thread visibility across the container. Inject ApplicationEventPublisher instead of the full ApplicationContext to improve interface segregation. Fixes gh-4570 Signed-off-by: Ali Ihsan TASDELEN <atasdelen@infodif.com> Signed-off-by: Ali Ihsan TASDELEN <alihsan.tsdln@gmail.com>
1 parent 9018406 commit 6ae2022

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerInitializerConfiguration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import org.apache.commons.logging.LogFactory;
2323
import org.springframework.cloud.netflix.eureka.server.event.EurekaRegistryAvailableEvent;
2424
import org.springframework.cloud.netflix.eureka.server.event.EurekaServerStartedEvent;
25-
import org.springframework.context.ApplicationContext;
2625
import org.springframework.context.ApplicationEvent;
26+
import org.springframework.context.ApplicationEventPublisher;
2727
import org.springframework.context.SmartLifecycle;
2828
import org.springframework.context.annotation.Configuration;
2929
import org.springframework.core.Ordered;
@@ -46,17 +46,17 @@ public class EurekaServerInitializerConfiguration implements SmartLifecycle, Ord
4646

4747
private final ServletContext servletContext;
4848

49-
private final ApplicationContext applicationContext;
49+
private final ApplicationEventPublisher applicationEventPublisher;
5050

5151
private final EurekaServerBootstrap eurekaServerBootstrap;
5252

5353
private volatile boolean running;
5454

5555
public EurekaServerInitializerConfiguration(EurekaServerConfig eurekaServerConfig, ServletContext servletContext,
56-
ApplicationContext applicationContext, EurekaServerBootstrap eurekaServerBootstrap) {
56+
ApplicationEventPublisher applicationEventPublisher, EurekaServerBootstrap eurekaServerBootstrap) {
5757
this.eurekaServerConfig = eurekaServerConfig;
5858
this.servletContext = servletContext;
59-
this.applicationContext = applicationContext;
59+
this.applicationEventPublisher = applicationEventPublisher;
6060
this.eurekaServerBootstrap = eurekaServerBootstrap;
6161
}
6262

@@ -84,7 +84,7 @@ private EurekaServerConfig getEurekaServerConfig() {
8484
}
8585

8686
private void publish(ApplicationEvent event) {
87-
this.applicationContext.publishEvent(event);
87+
this.applicationEventPublisher.publishEvent(event);
8888
}
8989

9090
@Override

0 commit comments

Comments
 (0)