bonjour,
je suis entrain d'essayé de faire un soft de test processeur.
mais voila j'ai quelque probleme

quand je lance mes thread, pas de problème, pas charge proco monte a 100%, par contre, aprés, dés que j'arrête le test (les trhead tourne dans une boucle infini ) l'occupation processeur ne retombe que a 50%........ puis aprés un nouvelle appuis sur lancé, la sa tombe a 0% et le test ne part pas....

aussi est-il est possible de mettre ma methode actionPerformed en dehors de la class de mon IHM ?

aussi, mes thread n'execute pas les boucles de ma class ou il y a mes tests.... mes, elle execute les instruction avant/aprés.....


sinon, question un peut specifique:
certain calcul processeur le font t'il plus chauffer que d'autre? car la, mon proco tourne a 100% mais ne chauffe pas beaucoup....

ma class ou va ce trouver l'algo de test
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
 
public class Algotest {
 
	public Algotest() {
		// le chrono bouffe bien en resource, a testé ;)
	}
 
	public void test() {
		// TODO Auto-generated method stub
 
		String strj = Thread.currentThread().getName();// donne nom thread
		if (strj.equals("th1")) {
			// ici, si je veut lancer une boucle, elle n'est pas effectué
			System.out.println("ici th1"); //executé
			for(int i=0;i>=10;i++)
			{
				System.out.println("i= "+i); // pas executé
			}
			System.out.println("ici th1 2");//executé
 
		}
		if (strj.equals("th2")) {
			// ici aussi
			System.out.println("ici th2");//executé
			for(int j=0;j>=10;j++)
			{
				System.out.println("j= "+j);// pas executé
			}
			System.out.println("ici th2 2");//executé
 
		}
		if (strj.equals("th3")) {
		}
		if (strj.equals("th4")) {
		}
		if (strj.equals("th5")) {
		}
		if (strj.equals("th6")) {
		}
		if (strj.equals("th7")) {
		}
		if (strj.equals("th8")) {
		}
 
	}
}
la class de l'IHM et le reste
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
//import javax.swing.event.*;
 
@SuppressWarnings("serial")
public class Ihmprocoswing extends JFrame implements ActionListener, Runnable {
 
	/**
         * @param args
         */
 
	private int seconde, minute;
	private long heure;
	private String temps;
 
	public Thread th1;
	public Thread th2;
	public Thread th3;
	public Thread th4;
	public Thread th5;
	public Thread th6;
	public Thread th7;
	public Thread th8;
	public Thread chrono;
 
	private JButton lancer;
	private JButton stop;
 
	private JLabel lab1;
	private JLabel lab2;
	public JLabel lab3;
	private JLabel lab4;
	public JLabel lab5;
	private JLabel lab6;
	private boolean autorisation = false;
	private boolean passage = false;
 
	private JComboBox cb;
 
	int nbProc = Runtime.getRuntime().availableProcessors();// permet de savoir
	// le nombre de
	// processeur
	String name = System.getProperty("os.name"); // donne le nom de l'os
	String version = System.getProperty("os.version"); // donne la version de
 
	// l'os
 
	public Ihmprocoswing() {
		// ===================IHM==================================
 
		setTitle("Test Processeur by Hannibal For hardware-pc ");
		setSize(650, 200);
		setLocation(500, 500);
		setLayout(new BorderLayout());
 
		Color col = new Color(15, 212, 214);
 
		JPanel pan1 = new JPanel(new GridLayout(1, 4, 3, 3));
		JPanel pan2 = new JPanel(new GridLayout(1, 4, 3, 3));
 
		// ===================NORTH========================
 
		// lancer = new JButton(new ImageIcon("image/lancer2.png"));
		lancer = new JButton("lancer");
		lancer.addActionListener(this);
		pan1.add(lancer);
 
		stop = new JButton("stop"); // a mettre image
		stop.addActionListener(this);
		pan1.add(stop);
 
		String combo[] = { "30 min", "1 Heure", "2 Heures", "4 Heures",
				"6 Heures", "Infini" }; // contenu de la comboBox
		cb = new JComboBox(combo);
		cb.addActionListener(this);
		pan1.add(cb);
 
		lab1 = new JLabel("OS: " + name + " | " + version);
		pan1.add(lab1);
 
		// ===================SOUTH========================
		lab2 = new JLabel("Temps écoulé: ");
		pan2.add(lab2);
 
		lab3 = new JLabel("00h00min00sec");
		pan2.add(lab3);
 
		lab4 = new JLabel("Temps Choisi: ");
		pan2.add(lab4);
 
		lab5 = new JLabel("00h30min00sec ");
		pan2.add(lab5);
 
		// ===================CENTER========================
 
		lab6 = new JLabel("PRET", JLabel.CENTER);
		add(lab6, BorderLayout.CENTER);
 
		// ================================================
 
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// fermeture fenetre
 
		chrono = new Thread(this);
		chrono.setName("chrono");
		pan1.setBackground(col);
		pan2.setBackground(col);
		add(pan1, BorderLayout.NORTH);
		add(pan2, BorderLayout.SOUTH);
 
		setVisible(true);
	}
 
	public void actionPerformed(ActionEvent e) {
 
		if (e.getSource() == lancer) {
			// verif pour ne pas essayé de lancé 2
			// fois les même Thread
			autorisation = true;
 
			if (passage == false) {
 
				try {
					// lancement des Thread
					switch (nbProc) {
					case 1:
						th1 = new Thread(this);
						th1.setName("th1"); // donne le nom th1 a la thread
						th1.start();
						break;// lancement d'un thread
 
					case 2:
						th1 = new Thread(this);
						th2 = new Thread(this);
						th1.setName("th1");
						th2.setName("th2");
						th1.start();
						th2.start();
						break;// lancement de 2 thread
 
					case 3:
						th1 = new Thread(this);
						th2 = new Thread(this);
						th3 = new Thread(this);
						th1.setName("th1");
						th2.setName("th2");
						th3.setName("th3");
						th1.start();
						th2.start();
						th3.start();
						break;
 
					case 4:
						th1 = new Thread(this);
						th2 = new Thread(this);
						th3 = new Thread(this);
						th4 = new Thread(this);
						th1.setName("th1");
						th2.setName("th2");
						th3.setName("th3");
						th4.setName("th4");
						th1.start();
						th2.start();
						th3.start();
						th4.start();
						break;
 
					case 5:
						th1 = new Thread(this);
						th2 = new Thread(this);
						th3 = new Thread(this);
						th4 = new Thread(this);
						th5 = new Thread(this);
						th1.setName("th1");
						th2.setName("th2");
						th3.setName("th3");
						th4.setName("th4");
						th5.setName("th5");
						th1.start();
						th2.start();
						th3.start();
						th4.start();
						th5.start();
						break;
 
					case 6:
						th1 = new Thread(this);
						th2 = new Thread(this);
						th3 = new Thread(this);
						th4 = new Thread(this);
						th5 = new Thread(this);
						th6 = new Thread(this);
						th1.setName("th1");
						th2.setName("th2");
						th3.setName("th3");
						th4.setName("th4");
						th5.setName("th5");
						th6.setName("th6");
						th1.start();
						th2.start();
						th3.start();
						th4.start();
						th5.start();
						th6.start();
						break;
 
					case 7:
						th1 = new Thread(this);
						th2 = new Thread(this);
						th3 = new Thread(this);
						th4 = new Thread(this);
						th5 = new Thread(this);
						th6 = new Thread(this);
						th7 = new Thread(this);
						th1.setName("th1");
						th2.setName("th2");
						th3.setName("th3");
						th4.setName("th4");
						th5.setName("th5");
						th6.setName("th6");
						th7.setName("th7");
						th1.start();
						th2.start();
						th3.start();
						th4.start();
						th5.start();
						th6.start();
						th7.start();
						break;
 
					case 8:
						th1 = new Thread(this);
						th2 = new Thread(this);
						th3 = new Thread(this);
						th4 = new Thread(this);
						th5 = new Thread(this);
						th6 = new Thread(this);
						th7 = new Thread(this);
						th8 = new Thread(this);
						th1.setName("th1");
						th2.setName("th2");
						th3.setName("th3");
						th4.setName("th4");
						th5.setName("th5");
						th6.setName("th6");
						th7.setName("th7");
						th8.setName("th8");
						th1.start();
						th2.start();
						th3.start();
						th4.start();
						th5.start();
						th6.start();
						th7.start();
						th8.start();
						break;
					}
				} catch (Exception exc) {
					System.out
							.println("probleme dans le lancements des thread");
					System.exit(0);
				}
 
			}
 
			switch (cb.getSelectedIndex()) {
			case 0:
				lab5.setText("00h30min00sec");
				temps = "0h30min0sec";
				break;
 
			case 1:
				lab5.setText("01h00min00sec");
				temps = "1h0min0sec";
				break;
 
			case 2:
				lab5.setText("02h00min00sec");
				temps = "2h0min0sec";
				break;
 
			case 3:
				lab5.setText("04h00min00sec");
				temps = "4h0min0sec";
				break;
 
			case 4:
				lab5.setText("06h00min00sec");
				temps = "6h0min0sec";
				break;
 
			case 5:
				lab5.setText("INFINI");
				temps = "attendre";
				break;
			}
 
			if (!passage) { // test si deja passer
				passage = true;
				chrono.start();
 
			}
			lab6.setText("Test en Cour");
		} else {
 
			if (e.getSource() == stop) {
				autorisation = false;
				seconde = 0;
				minute = 0;
				heure = 0;
				lab3.setText(heure + "h" + minute + "min" + seconde + "sec");
				lab5.setText("00h30min00sec");
				cb.setSelectedIndex(0);
				lab6.setText("PRET");
 
			}
		}
	}
 
	@Override
	public void run() {
		// TODO Auto-generated method stub
		String strj = Thread.currentThread().getName();// donne nom thread
		// apellante
 
		// =============== Chrono=====================
		if (strj.equals("chrono")) {
			while (true) {
				while (!lab3.getText().equals(temps)) {
 
					if (autorisation) {
 
						lab3.setText(heure + "h" + minute + "min" + seconde
								+ "sec");
						try {
							Thread.sleep(1000);
						} catch (InterruptedException e) {
							System.out
									.println("Probleme dans le temps du chrono");
						}
 
						seconde++;
						if (seconde == 60) {
							seconde = 00;
							minute++;
						}
						if (minute == 60) {
							minute = 00;
							heure++;
						}
 
					}
 
				}
 
				if (lab3.getText().equals(temps)) {
 
					autorisation = false;
					seconde = 0;
					minute = 0;
					heure = 0;
					lab3
							.setText(heure + "h" + minute + "min" + seconde
									+ "sec");
					lab5.setText("00h30min00sec");
					cb.setSelectedIndex(0);
					lab6.setText("Test Terminé / PRET");
 
				}
			}
		}
		// =================== Test=====================
		if (strj.equals("th1") || strj.equals("th2") || strj.equals("th3")
				|| strj.equals("th4") || strj.equals("th5")
				|| strj.equals("th6") || strj.equals("th7")
				|| strj.equals("th8")) {
 
			while (autorisation) {
 
				// Algotest algo = new Algotest();
				// algo.test();
 
			}
		}
	}
 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Ihmprocoswing();
 
	}
 
}
merci d'avance de votre aide