title: How can a Spring Application be made to be single threaded or made to have one instance?
body: <p>I have a Spring application that is controlled with an API that we need to be single threaded, but I can not figure out how to accomplish this. The application is a re-factoring of an app that is single threaded. They want the same basic design for the new version, while using our new programming methods (i.e. Java, Spring, etc.) and adding extra functionality.</p>
  
  <p>There is an API resource to start the application:</p>
  
  <pre><code>@RequestMapping("/start")
  public String startProcess(){...}
  </code></pre>
  
  <p>If this gets called twice then the application will start another thread. <strong>We want to stop this from happening</strong>. But, we still want the stop API resource to work:</p>
  
  <pre><code>@RequestMapping("/stop")
  public String stopProcess(){...}
  </code></pre>
  
  <p>The app has a typical Spring structure:</p>
  
  <pre><code>@SpringBootApplication
  public class MyApplication{...}
  
  @RestController
  public class MyController{   
      @Autowired
      private MyService myService;
      ...}
  
  @Service
  @Transactional
  public class CarolService{
      @Autowired
      private MyDAO myDAO;
      ...}
  
  @Repository
  public class myDAO{...}
  </code></pre>
  
  <p>How do I make sure that there is only one instance of this application running at a time? Please Help! And, thanks in advance!</p>