le voici :
A l'intérieure des methodes Cycle() j'utilise testFin() quelques fois pour arreter mon thread quand je clic sur un bouton qui me met ma variable stopThread à true.
Lors d'un clic sur ce bouton , la methode tesFin() s'execute car j'obtiens dans la console : java.lang.InterruptedException. Problème le thread ne s'arrete po
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
42
43
44
45
46
47
48
49
50
51 public class Histo extends Thread { private int nb=0, nbDD=0; private Date date; private GetSNMP gsnmp; private Poster mail; private String[] elements; private Elements el; private PingElement pe; private String[] tabR; private long idElement; private Locale locale; private DateFormat dateFormat; private DataBas db; private ResultSet rs; private long temps; private boolean stopThread = false; private boolean stopThread = false; public Histo(String tps) { temps=Long.parseLong(tps); this.start(); } public synchronized void arret() { stopThread = true; } public void run() { try { while (true){ el = new Elements(); Cycle("sgsf_mon",0); //Switch et Routeurs Cycle("sgsf_mon",1); //Serveurs et Flexnet Cycle("sgsf_mon",2); //Points acces Thread.sleep(temps*1000); } }catch( InterruptedException e ) { System.out.println(e); } } public synchronized void testFin() throws InterruptedException { if( stopThread ) { throw new InterruptedException(); } }![]()
Partager