Ensuring Single Instance of SpringBoot Application

Viewed 1263

How can I ensure only single instance of my SpringBoot Application should run.

I am starting my spring boot application with java -jar target/myproject-0.0.1-SNAPSHOT.jar

I need to ensure that if someone run this command second time on the same JVM,my application should not start. One approach can be to create a lock file at the application startup and delete the lock file at application shutdown.But this will require a lot of boiler plate code. Is there any better approach to do this Spring Boot?

1 Answers
Related