title: How to keep my program alive for as long a daemon thread is running?
body: <p>I have a requirement, that I want to start a poller once which will run foreever until the machine is restarted or the process is being killed. Now, I tried to start the poller from a main method using a shell script, but the problem is that as soon as the main method completed its execution, the poller also stoped working, as i am not using any servers to achieve so.</p>
  
  <p>I heard something about <code>daemon threads</code>, but I am wondering how to create a daemon thread, which will run forever, and help my poller to run also.</p>
  
  <p>UPDATE:</p>
  
  <pre><code>public class SomeThread extends Thread {
  
      @Override
      public void run() {
          UnitPoller unitPoller = new UnitPoller();
          unitPoller.doPolling();
      }
  
      public static void main(String[] args) {
          SomeThread someThread = new SomeThread();
          someThread.setDaemon(true);
          someThread.start();
      }
  }
  </code></pre>
  
  <p>Above is my updated class, now whenever I execute this thread from the main method, it creates a thread but as soon as the execution of main method completes, my poller stops working, as the JVM shuts down.</p>
  
  <p>With this problem, what should i do.</p>
  
  <p>Thanks</p>