Threads java
Fermé
gilles81
Messages postés
67
Date d'inscription
mardi 20 mai 2008
Statut
Membre
Dernière intervention
29 juillet 2009
-
26 nov. 2008 à 15:14
kilian Messages postés 8732 Date d'inscription vendredi 19 septembre 2003 Statut Modérateur Dernière intervention 5 février 2025 - 26 nov. 2008 à 17:25
kilian Messages postés 8732 Date d'inscription vendredi 19 septembre 2003 Statut Modérateur Dernière intervention 5 février 2025 - 26 nov. 2008 à 17:25
Bonjour,
je ne comprend toujours pas ce que fait un deamon threads? Est ce un threads qui fonctionne en invisible?
merci
je ne comprend toujours pas ce que fait un deamon threads? Est ce un threads qui fonctionne en invisible?
merci
A voir également:
- Threads java
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel football - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Waptrick java voiture - Télécharger - Jeux vidéo
- Java décompiler - Télécharger - Langages
3 réponses
kilian
Messages postés
8732
Date d'inscription
vendredi 19 septembre 2003
Statut
Modérateur
Dernière intervention
5 février 2025
1 526
26 nov. 2008 à 15:30
26 nov. 2008 à 15:30
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.
Il s'agit souvent d'un logiciel qui fait office de serveur.
gilles81
Messages postés
67
Date d'inscription
mardi 20 mai 2008
Statut
Membre
Dernière intervention
29 juillet 2009
1
26 nov. 2008 à 15:58
26 nov. 2008 à 15:58
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
/******************************
* 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
kilian
Messages postés
8732
Date d'inscription
vendredi 19 septembre 2003
Statut
Modérateur
Dernière intervention
5 février 2025
1 526
26 nov. 2008 à 17:25
26 nov. 2008 à 17:25
C'est la méthode run()
un thread démon en fait c'est ça:
https://fr.wikipedia.org/wiki/Daemon
un thread démon en fait c'est ça:
https://fr.wikipedia.org/wiki/Daemon