Skip to content

Commit

Permalink
[MINOR] ConfigurationWrapper class adds thread pool shutdown (#683)
Browse files Browse the repository at this point in the history
* gradle

* ConfigurationWrapper class adds thread pool shutdown
  • Loading branch information
li-xiao-shuang authored Dec 31, 2021
1 parent 42decd4 commit 647a7d3
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.commons.lang3.StringUtils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
Expand All @@ -37,12 +36,14 @@
public class ConfigurationWrapper {

public Logger logger = LoggerFactory.getLogger(this.getClass());


private static final long TIME_INTERVAL = 30 * 1000L;

private String file;

private Properties properties = new Properties();

private boolean reload = true;
private boolean reload;

private ScheduledExecutorService configLoader = ThreadPoolFactory.createSingleScheduledExecutor("eventMesh-configLoader-");

Expand All @@ -55,19 +56,18 @@ public ConfigurationWrapper(String file, boolean reload) {
private void init() {
load();
if (this.reload) {
configLoader.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
load();
}
}, 30 * 1000, 30 * 1000, TimeUnit.MILLISECONDS);
configLoader.scheduleAtFixedRate(this::load, TIME_INTERVAL, TIME_INTERVAL, TimeUnit.MILLISECONDS);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
logger.info("Configuration reload task closed");
configLoader.shutdownNow();
}));
}
}

private void load() {
try {
logger.info("loading config: {}", file);
properties.load(new BufferedReader(new FileReader(new File(file))));
properties.load(new BufferedReader(new FileReader(file)));
} catch (IOException e) {
logger.error("loading properties [{}] error", file, e);
}
Expand Down

0 comments on commit 647a7d3

Please sign in to comment.