title: Use of Thread.currentThread().join() in Java
body: <p>The following code is taken from an example in the Jersey project. See <a href="https://github.com/jersey/jersey/blob/2.22.1/examples/helloworld/src/main/java/org/glassfish/jersey/examples/helloworld/App.java" rel="noreferrer">here</a>.</p>
  
  <pre><code>public class App {
  
      private static final URI BASE_URI = URI.create("http://localhost:8080/base/");
      public static final String ROOT_PATH = "helloworld";
  
      public static void main(String[] args) {
          try {
              System.out.println("\"Hello World\" Jersey Example App");
  
              final ResourceConfig resourceConfig = new ResourceConfig(HelloWorldResource.class);
              final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, resourceConfig, false);
              Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
                  @Override
                  public void run() {
                      server.shutdownNow();
                  }
              }));
              server.start();
  
              System.out.println(String.format("Application started.\nTry out %s%s\nStop the application using CTRL+C",
                      BASE_URI, ROOT_PATH));
  
              //////////////////////////////
              Thread.currentThread().join();
              //////////////////////////////
  
          } catch (IOException | InterruptedException ex) {
              //
          }
  
      }
  }
  </code></pre>
  
  <p>I understand what is going on apart from the use of <code>Thread.currentThread().join();</code>. </p>
  
  <p>I'm a Java newbie and my understanding is that this will block the execution of the current thread (in this case, the main thread), and effectively deadlock it. i.e. it will cause the current (main) thread to block until the current (main) thread finishes, which will never happen. </p>
  
  <p>Is this correct? If so, why is it there?</p>