title: Restart Swing Application
body: <p>I am willing to add a button in my application which on-click will restart the app. I searched Google but found nothing helpful except <a href="http://www.jroller.com/santhosh/entry/make_you_application_restart_on" rel="nofollow noreferrer">this one</a>. But the procedure follows here is violating the WORA concept of Java. </p>
  
  <p>Is there any other Java centric way to achieve this feature? Is it possible to just fork another copy and then exit?</p>
  
  <p>Thanks in advance. I appreciate your help.</p>
  
  <hr>
  
  <p>@deporter I have tried your solution but it is not working :(</p>
  
  <p>@mKorbel I wrote the following code by taking concept you had shown in <a href="https://stackoverflow.com/questions/6121990/pass-string-as-params-from-one-java-app-to-another">so</a></p>
  
  <pre><code>    JMenuItem jMenuItem = new JMenuItem("JYM");
      jMenuItem.addActionListener(new ActionListener() {
  
          @Override
          public void actionPerformed(ActionEvent e) {
  
              ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(10);
              executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
              executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(true);
              ScheduledFuture&lt;?&gt; future = executor.schedule(new Runnable() {
  
                  @Override
                  public void run() {
                      try {
                          Process p = Runtime.getRuntime().exec("cmd /c start java -jar D:\\MovieLibrary.jar");
                      } catch (IOException ex) {
                          ex.printStackTrace();
                      }
                  }
              }, 2, TimeUnit.SECONDS);                
              executor.shutdown();
              try {
                  executor.awaitTermination(10, TimeUnit.SECONDS);
              } catch (InterruptedException e1) {
                  e1.printStackTrace();
              }
  
              System.exit(0);
          }
      });
  </code></pre>
  
  <p>And also:</p>
  
  <pre><code>ScheduledExecutorService schedulerExecutor = Executors.newScheduledThreadPool(2);
              Callable&lt;Process&gt; callable = new Callable&lt;Process&gt;() {
  
                  @Override
                  public Process call() throws Exception {
                      Process p = Runtime.getRuntime().exec("cmd /c start java -jar D:\\MovieLibrary.jar");
                      return p;
                  }
              };
              FutureTask&lt;Process&gt; futureTask = new FutureTask&lt;Process&gt;(callable);
              schedulerExecutor.submit(futureTask);
              schedulerExecutor.shutdown();
              try {
                  schedulerExecutor.awaitTermination(10, TimeUnit.SECONDS);
              } catch (InterruptedException e1) {
                  e1.printStackTrace();
              }
  
              System.exit(0);
  </code></pre>
  
  <p>its working but only once. If I launch the application for first time and press JYM menuitem then it shutdowns and after few second it opens a new ui with cmd, but if I press that JYM menuitem the application terminate completely, i.e., it is not again launches anymore.</p>
  
  <p>I really appreciate your help.</p>
  
  <hr>
  
  <p>It is solved.</p>