title: Exception Handling in case of Thread.sleep and wait() method in case of Threads
body: <p>I was trying to write a Producer Consumer model (Producer thread and Consumer Thread in java)</p>
  
  <p>I was wondering how to handle the <code>InterruptedException</code> that is thrown by <code>Thread.sleep</code> method and the <code>Object</code> Class's <code>wait()</code> method</p>
  
  <pre><code>package producerconsumer;
  
  import java.util.ArrayList;
  
  public class Consumer implements Runnable {
  
      ArrayList&lt;Integer&gt; container;
  
      @Override
      public void run() {
          while(true){
          System.out.println("Consumer Thread Running");
          try {
              Thread.sleep(1000);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
          if(null==container){
              System.out.println("container is null");
          }
          //Removing values from Arraylist
          synchronized (container) {
              if(container.size()==0){
                  try {
                      container.wait();
                  } catch (InterruptedException e) {
                      //How to tackle this exception
                      e.printStackTrace();
                  }
              }
              Integer removedInteger = container.remove(container.size()-1);
              System.out.println("removedInteger..."+removedInteger);
          }
          }
      }
  
      public void setContainer(ArrayList&lt;Integer&gt; container) {
          this.container = container;
      }
  }
  </code></pre>
  
  <p>This is one example I have taken, In this example there may not be any need to take care of these exception (My Assumption).</p>
  
  <p><strong>But I wanted to know what could be the different scenarios possible in which we need to handle this exception.</strong></p>