Bonjour,

Je suis sur un problème d'arrêt de thread.
J'ai consulté la FAQ, mais il doit me manquer quelque chose.

J'ai un JDialog qui contient son propre thread. J'ai ajouté un windowLinstener pour qu'à la fermeture je puisse fermer cette JDialog, mais également fermer le thread associé.

Le code épuré donne :
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 
public class jpPopup extends JDialog implements Runnable,WindowListener
{
	private Thread t;
	private boolean isTRun;
	private boolean isPlay;
	private boolean isStop;
 
	public jpPopup()
	{
		super();
		this.isPlay=false;
		this.isStop=false;
		this.isTRun=true;
		this.pack();
		this.setVisible(true);
		this.addWindowListener(this);
 
		this.t=new Thread(this);
		this.t.start();
	}
 
	public void run()
	{
		while(this.isTRun)
		{
			try
			{
				System.out.println("(jpPopupSon - run) isPlay : "+this.isPlay+" -- isStop : "+this.isStop);
 
				if(this.isPlay)
					testStop();
				else
				{
					//TRAITEMENT
					this.isPlay=true;
				}
 
				Thread.sleep(1000);
			}
			catch(InterruptedException e)
			{
				System.out.println("(jpPopupSon - InterruptedException)");
				e.printStackTrace();
				this.isTRun=false;
			}
		}
	}
 
 
	public synchronized void testStop() throws InterruptedException
	{
		System.out.println("(jpPopupSon - testStop)");
		if(this.isStop)
			throw new InterruptedException();
	}
 
 
	public synchronized void tStop()
	{
		this.isStop=true;
	}
 
	public void windowClosing(WindowEvent e)
	{
		System.out.println("(jpPopupSon - windowClosing)");
		tStop();
	}
}
Merci d'avance