Reputation: 41
I encounter a problem that my springboot project will shutdown and restart automatically. Before that problem, the program finish schedule job, this scheduling job will read data from redis and then compare with local backup file, if any new data coming up, the program will write to local backup file. The following part is the shutdown log console log
Upvotes: 2
Views: 5406
Reputation: 21
You can add the Shutdown hook in my application.
Java shutdown hook runs in these two cases.
Code:
Runtime.getRuntime().addShutdownHook(new Thread("Shutdownhook") {
public void run() {
//code here
//compare redis cache
//syn data and save local file.
try {
mainThread.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
instance.logger.error(e.getMessage(), e);
}
}
});
Upvotes: 1
Reputation: 574
Incase if you are using spring-boot-devtools dependency in your pom.xml file, when any new changes are made to existing project it will automatically restart the project. It helps in cases where on making minor changes, the project is automatically restarted and the application start time is also significantly small compared to normal scenario. If you don't wish to have this behavior you can just remove the following dependency from you pom.xml file, thereby there is no automatic restart of application.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
Upvotes: 8