Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public class Th1 extends Thread{ private boolean arret=false; public void run(){ int i=0; while(!arret){ System.out.println(" "+i++); } } public void arret(){ arret=true; } } _________________________________________ public class Th2 extends Thread{ public void run(){ long duree=10000; long t1=System.currentTimeMillis(); System.out.println("t1 ="+t1); long t=0; while(t<duree){ t=System.currentTimeMillis()-t1; } MonThread.t1.arret(); } } _________________________________________ public class MonThread { static Th1 t1; static Th2 t2; public static void main(String[] args){ t1=new Th1(); Th2 t2=new Th2(); t1.start(); t2.start(); } }
Salut tout le monde. Je suis entrain d'étudier les Threads, I kindly ask u the following questions :
1- Dans Main , le mot clé static est utilisé pour déclarer les threads , pourquoi ?
2- Concernant la classe Th2, j'ai pas bien assimilé le fonctionnement du Time , que représente la variable t ?
Partager