title: How to automatically call a method to stop a thread?
body: <p>I'm realizing a little project in which female viviparous animals can have a gestation (a class which implements Runnable).</p>
  
  <p>Here's my Gestation class :</p>
  
  <pre><code>private final class Gestation implements Runnable //inner class of Viviparous
  {                                                
          private boolean isWorking;
          private Viviparous[] babies;
          private final int time_end;
          private int time_left;
          private Enclosure e;
  
          public Gestation(Viviparous[] b, Enclosure e)
          {
              if(Viviparous.this instanceof Lion) 
                  this.time_end = Lion.TIME_GESTATION;
              else if(Viviparous.this instanceof Gazelle) 
                  this.time_end = Gazelle.TIME_GESTATION;
              else if(Viviparous.this instanceof Otter) 
                  this.time_end = Otter.TIME_GESTATION;
              else
                  this.time_end = 0;
              this.time_left = this.time_end;
              this.e = e;
              this.b =b;
  
              this.isWorking = true;
              new Thread(this).start();
          }
  
          public Viviparous[] getBabies()
          {
              return this.babies;
          }
  
          public boolean isWorking()
          {
              return this.isWorking;
          }
  
          public void stop()
          {
              if(this.time_left == 0)
              {
                  Thread.currentThread().stop();
                  this.isWorking = false;
                  System.out.println("Gestation ended");
  
                  Viviparous.this.calve(this.e); //calving in Enclosure e.
              }
          }
  
          public void run() 
          {
              while(this.isWorking)
              {
                  this.time_left--;
                  try 
                  {
                      Thread.sleep(400L);
                  } 
                  catch (InterruptedException e) 
                  {
                      e.printStackTrace();
                  }
                  if((this.time_left)%10==0 &amp;&amp; this.time_left != 0)
                      System.out.println("Gestation will end in "+this.time_left+" days.");
              }
          }
  
  }
  </code></pre>
  
  <p>I would like to trigger stop() when time_left == 0.
  Right before I haven't had stop() method, only run() in which the loop stopped when time_left == time_end then called calve() of Viviparous.this, this last method asks the user to name the babies with an input.
  The problem is that my programm already asks the user to select an option from the current menu :
  I guess there's a conflict between entering babies name and menu option.</p>