title: Java - Thread.sleep in the main method
body: <p>I'm reviewing Java code that essentially is a recurring process that moves/reads/parses some files on regular basis and outputs data into the database. The repeating part is done (roughly) as follows:</p>
  
  <pre><code>public class CollectorMain {
      public static boolean signalRecieved = false;
      public static void main(String[] args) {
           Runtime.getRuntime().addShutdownHook(new Thread() {
                public void run() {  
                shutdown(); 
           }});
           while(!signalRecieved) {
                Collector.execute();
                try {
                    Thread.sleep(60 * 1000);
                } catch (InterruptedException e) {
                    break;
                }
           }
           // some shutdown logic
      }
      public static void shutdown() {
          signalReceived = true;
      }
  }
  
  public class Collector() {
      public static void execute() {
          // Move files from the queue dir to temp location
          // Read, parse files and insert records into database. 
          // Then delete the processed files
      }
  }
  </code></pre>
  
  <p>My recommendation was to refactor code to </p>
  
  <ol>
  <li>Create instance of Collector and refactor static execute() method to the instance method</li>
  <li>To use Runnable or TimerTask to handle invocations</li>
  </ol>
  
  <p>My argument was that using Thread.wait from the main method and combining it with static access is not a good way of handling repeatable process especially doing file IO. To which the author replied (quoting) </p>
  
  <blockquote>
    <p>The description of Runnable says "should be implemented by any class
    whose instances are intended to be executed by a thread". In fact, I
    am intentionally avoiding threads in this program, for reasons of cost
    vrs.performance requirements.</p>
  </blockquote>
  
  <p>Here's another quote from same discussion which will hopefully help to clarify the author's position</p>
  
  <blockquote>
    <p>Technically, Java isn't executed at all, it is interpreted by the JVM
    which then executes machine instructions, to simulate that the Java
    code is executing. So it's really the JVM that is executing on a
    thread, or multiple threads. </p>
    
    <p>But as a Java code writer, I don't care. If I don't create "threads"
    in Java, then It's the job of the JVM to appear as if there are no
    threads — even if the JVM is using threads "under the covers". </p>
    
    <p>A Java Pause is not executed, it is simulated by a sequence of machine
    instructions that may or may not call an OS 'wait'. (It probably does,
    because the JVM would not want to spin, burning CPU cycles, but that's
    a JVM implementation choice).</p>
  </blockquote>
  
  <p>So I have 2 questions:</p>
  
  <ol>
  <li>Is putting <code>Thread.wait</code> into the main method legit, safe and advisable way of doing repeatable task in this instance? And if not, why not since there's only one (main) thread of execution?</li>
  <li>What are the pitfals of using static metods in this context (if any)?</li>
  </ol>
  
  <p>I'll be happy to provide additional info if you have any other questions.</p>