Bonjour,

Je lance un outils qui me recrache les versions des plugins de mon eclipse, c'est juste du texte agrémenté de quelques balises html.
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
 
public void takeVersions()
{
	Process proc = null;
	try {
		proc = Runtime.getRuntime().exec("sxversions.exe --html");
		} catch (IOException e) {
			e.printStackTrace();
		}
	InputStream out = proc.getInputStream();
	MyBuffer bufferOut = new MyBuffer();
	MyThread readOutThread = new MyThread(bufferOut, out);
	try {
		proc.getOutputStream().close();
	} catch (IOException e2) {
		e2.printStackTrace();
	}
 
	readOutThread.start();
 
	// STDOUT
	String sOut;
	int nbTgt = 0;
 
	try{
		fAboutHtml = File.createTempFile("aboutVersions", ".html");
		fAboutHtml.deleteOnExit();
		BufferedWriter stdin = new BufferedWriter(new FileWriter(fAboutHtml));
 
		while ((sOut = bufferOut.get()) != null) {
			nbTgt++;
			if(!sOut.isEmpty()) {
				stdin.write(sOut);
				stdin.newLine();
			}
			stdin.close();
		}catch (IOException e) {
	}
}
// Class MyBuffer to stock my feedbacks
class MyBuffer {
	private List<String> list;
	private int nbConnected;
 
	@SuppressWarnings("unchecked")
	public MyBuffer() {
		list = Collections.synchronizedList(new LinkedList());
		nbConnected = 0;
	}
 
	public void add(String s) {
		synchronized (list) {
			list.add(s);
			list.notify();
		}
	}
 
	public String get() {
		System.err.flush();
		String s;
		synchronized (list) {
			if (list.size() == 0) {
				try {
					list.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			s = (String) list.remove(0);
		}
		return s;
	}
 
	public void connect() {
		nbConnected++;
	}
 
	public void disconnect() {
		nbConnected--;
		if (nbConnected == 0) {
			add(null);
		}
	}
}
 
// ////////////Class MyThread to create my buffer readers
class MyThread extends Thread {
	private MyBuffer buffer;
	private InputStream in;
 
	public MyThread(MyBuffer buffer, InputStream in) {
		this.in = in;
		this.buffer = buffer;
		buffer.connect();
	}
 
	public void run() {
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		String s;
		try {
			while ((s = br.readLine()) != null) {
				buffer.add(s);
			}
			in.close();
			buffer.disconnect();
		} catch (IOException e) {
			e.printStackTrace();
	}
}
ça marche très bien sauf que mon while prends des plombes ... style 5à7 secondes pour parcourir les 194 enregistrements (nb de nbTgt):
while ((sOut = bufferOut.get()) != null) {

J'arrive pas à voir ce qui cloche dans mon code.
Une idée afin d'optimiser un peu ???