title: How to run a Thread for a user specified amount of time?
body: <p>Am creating a program that is based on mixing and making perturbation in a population containing solutions <code>Vector</code>.</p>
  
  <p><strong>So I created a <code>for loop</code> that stops after a certain time given by the user.</strong> 
  Inside the loop, am going to call 5 procedures and I thought that if i put each procedure in a thread will make the program making more solutions in a same time than calling normal methods.</p>
  
  <p>Here 5 created the 5 threads, but when i start them the don't want to stop even if i use the <code>Thread.stop</code>, <code>Thread.suspend</code>, <code>Thread.interrupt</code> or <code>Thread.destroy</code> <br></p>
  
  <p>Here is my code and could u help me with your ideas ?<br></p>
  
  <p>I have inserted a new variable :<br></p>
  
  <pre><code>public volatile boolean CrossOpb = true;`
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>Thread CrossOp = new Thread(new Runnable() {
  public void run() {
     while(CrossOpb == true){
      int rdmCross2=(int) (Math.random() * allPopulation.size())  ; // Crossover 1st vector
      int rdmCross1=(int) (Math.random() * allPopulation.size())  ;
      Vector muted = new Vector();
      Vector copy = copi((Vector) allPopulation.get(rdmCross2));
      Vector callp = copi((Vector) allPopulation.get(rdmCross1));
      muted = crossover(callp, copy);
      System.out.println("cross over Between two Randoms -----------&gt;");
      affiche_resultat(muted);
      allPopulation.add(muted);
     }
  }
  </code></pre>
  
  <p>});</p>
  
  <p>The loop : </p>
  
  <pre><code>CrossOp.setDaemon(true);
  
  int loop = 1;
  long StartTime = System.currentTimeMillis() / 1000;
  for (int i = 0; i &lt; loop; ++i) { 
      loop++;
      if (timevalue &lt; ((System.currentTimeMillis() / 1000) - StartTime)) {
          loop = 0;
       CrossOpb = false;   
      }
  CrossOp.start();
  }
  </code></pre>