Threads java

Bonjour,
je ne comprend toujours pas ce que fait un deamon threads? Est ce un threads qui fonctionne en invisible?

merci
Configuration: Windows Vista
Firefox 3.0.4

3 réponses

  1. Modérateur
    Un démon souvent c'est un programme (ou sous-programme) qui tourne dans une boucle infinie.
    Il s'agit souvent d'un logiciel qui fait office de serveur.
    1. quel est la fonction exacte de deamon dans ce programme stp:

      /******************************
      * a simple thread example.
      * Two dependent threads started from main()
      * when main ends, the two deamons end, too
      * @author: Jaeger
      * @version 1.0
      *******************************/
      public class SchowDeamon extends Thread {

      private String word; //what to print
      private int delay; // how long to wait
      private int count; //how many ticks

      public SchowDeamon(String whatToSay, int delayTime, int howMany) {
      word = whatToSay;
      delay = delayTime;
      count = howMany;

      }

      public void run() {
      try {
      while (count > 0) {
      System.out.print (word +" ");
      //System.out.flush();
      count = count -1;
      Thread.sleep(delay); //stops a while, is interruptable now
      }
      System.out.println("thread terminated normally");
      }
      catch (InterruptedException e) {
      System.out.println("thread interrupted");
      Thread.currentThread().interrupt(); // end this thread
      }
      }

      private static void doSomething() {
      for (long i=0; i<7; i++) {i=i+1;i=i-1;}

      }

      public static void main (String[] args) {
      Thread child1 = new SchowDeamon("tick", 600, 3);
      child1.setDaemon(true); // makes the thread depenedend from the spawner
      child1.start();

      Thread child2 = new SchowDeamon("TOCK", 600, 4);
      child2.setDaemon(true); // makes the thread depenedend from the spawner
      child2.start();

      doSomething();

      System.out.println ("main ended");
      }

      }

      merci