Bonjour,

Je developpe un outil qui va tester differents environnement d'un même outil. Il s'agit d'un gros Outil de gestion present sur 8 machines differentes et comptant avec en tout 14 environement (instances).


L'API pour shooter l'outil est tres gourmande mais normallement la plus gros des instances ne demandent pas plus de 512 donc un Xmx512m devrait suffir...


Le problème est que ma mémoire ne smble être relaché depuis les threads...

Donc ca s'accumule et ca crash (pourtant je suis en Xmx1024 sur un poste en 2048)....

Voila code

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
 
package ppaceMaker;
 
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Iterator;
 
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
 
import utilities.MonAppli;
import utilities.Presta_XML;
import utilities.Utils;
 
import com.sciforma.psnext.api.PSException;
 
public class NonStaticFullConnectionDiagnosis {
 
	static final long start = System.currentTimeMillis();
 
	static long env_start_time = start;
 
	static long now = start;
 
	final boolean OK = true;
 
	private static int TIME_OUT = 300;
 
	private static final Logger logger = Logger.getLogger("PACEMAKER");
 
	static boolean timeOut = false;
 
	static boolean success = false;
 
	static Environment currentEnv;
 
	static Exception rootError;
 
	static ArrayList<Environment> environements;
 
	Thread tMonAppli;
 
	public NonStaticFullConnectionDiagnosis() {
	}
 
	private synchronized void lanchtest() throws PSException {
		MonAppli mytest = new MonAppli(currentEnv.getUsername(), currentEnv
				.getPassword(), currentEnv.getServerURL(), true, true);
		mytest.closeSession();
 
		long lUsedMemory = (Runtime.getRuntime().totalMemory() - Runtime
				.getRuntime().freeMemory()) / 1048576;
		logger.info("Used Memory: " + lUsedMemory + " Mo");
		logger.info("Total Memory : " + (Runtime.getRuntime().totalMemory())
				/ 1048576 + " Mo");
		mytest.freeSessionMemory();
		mytest = null;
 
		// System.gc();
 
		lUsedMemory = (Runtime.getRuntime().totalMemory() - Runtime
				.getRuntime().freeMemory()) / 1048576;
		logger.info("Used Memory: " + lUsedMemory + " Mo");
		logger.info("Total Memory : " + (Runtime.getRuntime().totalMemory())
				/ 1048576 + " Mo");
 
		System.gc();
 
		lUsedMemory = (Runtime.getRuntime().totalMemory() - Runtime
				.getRuntime().freeMemory()) / 1048576;
		logger.info("Used Memory: " + lUsedMemory + " Mo");
		logger.info("Total Memory : " + (Runtime.getRuntime().totalMemory())
				/ 1048576 + " Mo");
 
	}
 
	static ArrayList initializeOption() throws MalformedURLException,
			DocumentException {
 
		environements = new ArrayList<Environment>();
		Document EnvXML = Presta_XML.parse(ConnectionDiagnosis.class
				.getClassLoader().getResource("./conf/pacemaker.xml"));
 
		TIME_OUT = Integer.valueOf(EnvXML.getRootElement().element("options")
				.element("timeout").getText());
		Element environementsNodes = EnvXML.getRootElement().element(
				"environements");
 
		for (Iterator i = environementsNodes.elementIterator(); i.hasNext();) {
			Element curEnv = (Element) i.next();
 
			environements.add(new Environment(curEnv.attributeValue("user"),
					curEnv.attributeValue("pwd"), (String) curEnv
							.attributeValue("url"), Boolean.valueOf(curEnv
							.attributeValue("active"))));
 
		}
 
		return environements;
	}
 
	public void startEnvironement() {
 
		tMonAppli = new Thread(new Runnable() {
			public void run() {
				try {
					Thread.sleep(1);
					lanchtest();
					success = true;
				} catch (InterruptedException Ie) {
					rootError = Ie;
				} catch (PSException pse) {
					rootError = pse;
				} catch (Exception e) {
					rootError = e;
				}
			}
		});
 
		tMonAppli.start();
		try {
			tMonAppli.join(TIME_OUT * 1000);
			if (tMonAppli.isAlive()) {
				// Fin Echec
				// tMonAppli.interrupt();
				// PropertyConfigurator.
 
				tMonAppli.stop();
 
				while (rootError == null && !success) {
					Thread.sleep(1000);
				}
 
				logger.warn("Time Out! Starting disconnection");
 
				if (!logger.isInfoEnabled()) {
					// On réinitilaise log4j
					Logger.getRootLogger().removeAllAppenders();
					PropertyConfigurator.configure(ConnectionDiagnosis.class
							.getClassLoader().getResource(
									"conf/log4j.properties"));
				}
				// Traitement:
				logger.error(rootError);
				logger.error("Echec TimeOut");
 
			} else {
				// Fin Succes
				if (success) {
					logger.info("Reussite");
				} else {
 
					Thread.sleep(1000);
					Logger.getRootLogger().removeAllAppenders();
					PropertyConfigurator.configure(ConnectionDiagnosis.class
							.getClassLoader().getResource(
									"conf/log4j.properties"));
					// Erreur autre que TO
					logger.error(rootError);
				}
 
			}
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.err.println("LA3");
		} catch (Exception ex) {
			ex.printStackTrace();
			System.err.println("LA4");
		}
	}
 
	public static void main(java.lang.String[] args) {
 
		NonStaticFullConnectionDiagnosis FC = new NonStaticFullConnectionDiagnosis();
		PropertyConfigurator.configure(ConnectionDiagnosis.class
				.getClassLoader().getResource("conf/log4j.properties"));
 
		try {
			initializeOption();
		} catch (MalformedURLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			System.exit(-1);
		} catch (DocumentException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			System.exit(-1);
		}
 
		logger.info(environements.size() + " environments will be checked");
		logger.info("Starting Diagnosis");
		logger.info("Timeout :" + TIME_OUT + " s");
		int i = 0;
		for (Iterator iter = environements.iterator(); iter.hasNext();) {
			currentEnv = (Environment) iter.next();
			logger.info("Number: " + (++i));
			if (currentEnv.isActive()) {
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
 
				if (FC.tMonAppli != null
						&& (FC.tMonAppli.isAlive() || !FC.tMonAppli.isInterrupted())) {
					FC.tMonAppli.interrupt();
				}
 
				success = false;
				env_start_time = System.currentTimeMillis();
				FC.startEnvironement();
				logger.info("Executé en : "
						+ Utils.timeIt(env_start_time, false));
				// break;
			} else {
				logger.info(currentEnv.getServerURL() + " ignored");
			}
		}
 
		long lUsedMemory = (Runtime.getRuntime().totalMemory() - Runtime
				.getRuntime().freeMemory()) / 1048576;
		logger.info("Used Memory: " + lUsedMemory + " Mo");
		logger.info("Total Memory : " + (Runtime.getRuntime().totalMemory())
				/ 1048576 + " Mo");
		if (FC.tMonAppli != null)
			FC.tMonAppli.stop();
 
		System.gc();
		logger.info("Used Memory: " + lUsedMemory + " Mo");
		logger.info("Total Memory : " + (Runtime.getRuntime().totalMemory())
				/ 1048576 + " Mo");
 
		logger.info("Ending Diagnosis");
		Utils.timeIt(start, true);
		System.exit(0);
	}
}
Voila le Log:



[INFO ] [05-12-06 16:14:59] PACEMAKER : 14 environments will be checked
[INFO ] [05-12-06 16:14:59] PACEMAKER : Starting Diagnosis
[INFO ] [05-12-06 16:14:59] PACEMAKER : Timeout :600 s
[INFO ] [05-12-06 16:14:59] PACEMAKER : Number: 1
[INFO ] [05-12-06 16:15:00] PMONAPPLI : Connexion de admin sur http://instance:8080/pMONAPPLI
[INFO ] [05-12-06 16:16:05] PMONAPPLI : Connection established
[INFO ] [05-12-06 16:16:05] PMONAPPLI : Starting Resource import
[INFO ] [05-12-06 16:17:45] PMONAPPLI : 9381 resources loaded
[INFO ] [05-12-06 16:17:45] PMONAPPLI : Setting Resource Map by First and Last Name
[INFO ] [05-12-06 16:17:45] PMONAPPLI : Starting Project import
[INFO ] [05-12-06 16:17:48] PMONAPPLI : 2361 projects loaded
[INFO ] [05-12-06 16:17:48] PMONAPPLI : Setting Project Map by ID
[INFO ] [05-12-06 16:17:48] PMONAPPLI : Logging Out...
[INFO ] [05-12-06 16:17:48] PACEMAKER : Used Memory: 333 Mo
[INFO ] [05-12-06 16:17:48] PACEMAKER : Total Memory : 439 Mo
[INFO ] [05-12-06 16:17:48] PACEMAKER : Used Memory: 333 Mo
[INFO ] [05-12-06 16:17:48] PACEMAKER : Total Memory : 439 Mo
[INFO ] [05-12-06 16:17:49] PACEMAKER : Used Memory: 207 Mo
[INFO ] [05-12-06 16:17:49] PACEMAKER : Total Memory : 439 Mo
[INFO ] [05-12-06 16:17:49] PACEMAKER : Reussite
[INFO ] [05-12-06 16:17:49] PACEMAKER : Executé en : 00:02:49
[INFO ] [05-12-06 16:17:49] PACEMAKER : Number: 2
[INFO ] [05-12-06 16:17:50] PMONAPPLI : Connexion de admin sur http://instance2:8080/pMONAPPLI
[INFO ] [05-12-06 16:18:38] PMONAPPLI : Connection established
[INFO ] [05-12-06 16:18:38] PMONAPPLI : Starting Resource import
[INFO ] [05-12-06 16:20:25] PMONAPPLI : 9381 resources loaded
[INFO ] [05-12-06 16:20:25] PMONAPPLI : Setting Resource Map by First and Last Name
[INFO ] [05-12-06 16:20:25] PMONAPPLI : Starting Project import
[INFO ] [05-12-06 16:20:29] PMONAPPLI : 2361 projects loaded
[INFO ] [05-12-06 16:20:29] PMONAPPLI : Setting Project Map by ID
[INFO ] [05-12-06 16:20:29] PMONAPPLI : Logging Out...
[INFO ] [05-12-06 16:20:29] PACEMAKER : Used Memory: 594 Mo
[INFO ] [05-12-06 16:20:29] PACEMAKER : Total Memory : 651 Mo
[INFO ] [05-12-06 16:20:29] PACEMAKER : Used Memory: 594 Mo
[INFO ] [05-12-06 16:20:29] PACEMAKER : Total Memory : 651 Mo
[INFO ] [05-12-06 16:20:33] PACEMAKER : Used Memory: 361 Mo
[INFO ] [05-12-06 16:20:33] PACEMAKER : Total Memory : 651 Mo
[INFO ] [05-12-06 16:20:33] PACEMAKER : Reussite
[INFO ] [05-12-06 16:20:33] PACEMAKER : Executé en : 00:02:42
[INFO ] [05-12-06 16:20:33] PACEMAKER : Number: 3
[INFO ] [05-12-06 16:20:34] PMONAPPLI : Connexion de admin sur http://instance3:8080/pMONAPPLI
[INFO ] [05-12-06 16:21:25] PMONAPPLI : Connection established
[INFO ] [05-12-06 16:21:25] PMONAPPLI : Starting Resource import
[INFO ] [05-12-06 16:23:07] PMONAPPLI : 9381 resources loaded
[INFO ] [05-12-06 16:23:07] PMONAPPLI : Setting Resource Map by First and Last Name
[INFO ] [05-12-06 16:23:07] PMONAPPLI : Starting Project import
[INFO ] [05-12-06 16:23:10] PMONAPPLI : 2361 projects loaded
[INFO ] [05-12-06 16:23:10] PMONAPPLI : Setting Project Map by ID
[INFO ] [05-12-06 16:23:10] PMONAPPLI : Logging Out...
[INFO ] [05-12-06 16:23:11] PACEMAKER : Used Memory: 771 Mo
[INFO ] [05-12-06 16:23:11] PACEMAKER : Total Memory : 1016 Mo
[INFO ] [05-12-06 16:23:11] PACEMAKER : Used Memory: 771 Mo
[INFO ] [05-12-06 16:23:11] PACEMAKER : Total Memory : 1016 Mo
[INFO ] [05-12-06 16:23:14] PACEMAKER : Used Memory: 542 Mo
[INFO ] [05-12-06 16:23:14] PACEMAKER : Total Memory : 1016 Mo
[INFO ] [05-12-06 16:23:14] PACEMAKER : Reussite
[INFO ] [05-12-06 16:23:14] PACEMAKER : Executé en : 00:02:40
[INFO ] [05-12-06 16:23:14] PACEMAKER : Number: 4
[INFO ] [05-12-06 16:23:15] PMONAPPLI : Connexion de admin sur http://instance4:8080/pMONAPPLI
[INFO ] [05-12-06 16:24:03] PMONAPPLI : Connection established
[INFO ] [05-12-06 16:24:03] PMONAPPLI : Starting Resource import
[INFO ] [05-12-06 16:25:52] PMONAPPLI : 9381 resources loaded
[INFO ] [05-12-06 16:25:52] PMONAPPLI : Setting Resource Map by First and Last Name
[INFO ] [05-12-06 16:25:52] PMONAPPLI : Starting Project import
[INFO ] [05-12-06 16:25:55] PMONAPPLI : 2361 projects loaded
[INFO ] [05-12-06 16:25:55] PMONAPPLI : Setting Project Map by ID
[INFO ] [05-12-06 16:25:55] PMONAPPLI : Logging Out...
[INFO ] [05-12-06 16:25:55] PACEMAKER : Used Memory: 886 Mo
[INFO ] [05-12-06 16:25:55] PACEMAKER : Total Memory : 1016 Mo
[INFO ] [05-12-06 16:25:55] PACEMAKER : Used Memory: 886 Mo
[INFO ] [05-12-06 16:25:55] PACEMAKER : Total Memory : 1016 Mo
[INFO ] [05-12-06 16:26:00] PACEMAKER : Used Memory: 715 Mo
[INFO ] [05-12-06 16:26:00] PACEMAKER : Total Memory : 1016 Mo
[INFO ] [05-12-06 16:26:00] PACEMAKER : Reussite
[INFO ] [05-12-06 16:26:00] PACEMAKER : Executé en : 00:02:44
[INFO ] [05-12-06 16:26:00] PACEMAKER : Number: 5
[INFO ] [05-12-06 16:26:01] PMONAPPLI : Connexion de admin sur http://instance5:8080/copyprod
[INFO ] [05-12-06 16:26:46] PMONAPPLI : Connection established
[INFO ] [05-12-06 16:26:46] PMONAPPLI : Starting Resource import
[INFO ] [05-12-06 16:30:13] PMONAPPLI : 9365 resources loaded
[INFO ] [05-12-06 16:30:13] PMONAPPLI : Setting Resource Map by First and Last Name
[INFO ] [05-12-06 16:30:13] PMONAPPLI : Starting Project import
[INFO ] [05-12-06 16:30:33] PMONAPPLI : 2362 projects loaded
[INFO ] [05-12-06 16:30:33] PMONAPPLI : Setting Project Map by ID
[INFO ] [05-12-06 16:30:33] PMONAPPLI : Logging Out...
[INFO ] [05-12-06 16:30:33] PACEMAKER : Used Memory: 1015 Mo
[INFO ] [05-12-06 16:30:33] PACEMAKER : Total Memory : 1016 Mo
[INFO ] [05-12-06 16:30:33] PACEMAKER : Used Memory: 1015 Mo
[INFO ] [05-12-06 16:30:33] PACEMAKER : Total Memory : 1016 Mo
[INFO ] [05-12-06 16:30:38] PACEMAKER : Used Memory: 894 Mo
[INFO ] [05-12-06 16:30:38] PACEMAKER : Total Memory : 1016 Mo
[INFO ] [05-12-06 16:30:44] PACEMAKER : Reussite
[INFO ] [05-12-06 16:30:44] PACEMAKER : Executé en : 00:04:43
[INFO ] [05-12-06 16:30:44] PACEMAKER : Number: 6
[INFO ] [05-12-06 16:30:45] PMONAPPLI : Connexion de admin sur http://instance6:18080/certif
Exception in thread "Thread-7" java.lang.OutOfMemoryError: Java heap space
[ERROR] [05-12-06 16:35:36] PACEMAKER :
[INFO ] [05-12-06 16:35:36] PACEMAKER : Executé en : 00:04:50
[INFO ] [05-12-06 16:35:36] PACEMAKER : Number: 7
[INFO ] [05-12-06 16:35:37] PMONAPPLI : Connexion de admin sur http://instance7:28080/dev
Exception in thread "Thread-8" java.lang.OutOfMemoryError: Java heap space
[ERROR] [05-12-06 16:36:28] PACEMAKER :
[INFO ] [05-12-06 16:36:28] PACEMAKER : Executé en : 00:00:51
[INFO ] [05-12-06 16:36:28] PACEMAKER : Number: 8
[INFO ] [05-12-06 16:36:35] PMONAPPLI : Connexion de admin sur http://instance8:28080/pMONAPPLI_interfaces
Exception in thread "Thread-9" java.lang.OutOfMemoryError: Java heap space
[ERROR] [05-12-06 16:37:20] PACEMAKER :
[INFO ] [05-12-06 16:37:20] PACEMAKER : Executé en : 00:00:44
[INFO ] [05-12-06 16:37:20] PACEMAKER : Number: 9
[INFO ] [05-12-06 16:37:25] PMONAPPLI : Connexion de admin sur http://instance9:28080/homol
Exception in thread "Thread-10" java.lang.OutOfMemoryError: Java heap space
[ERROR] [05-12-06 16:38:33] PACEMAKER :
[INFO ] [05-12-06 16:38:33] PACEMAKER : Executé en : 00:01:07
[INFO ] [05-12-06 16:38:33] PACEMAKER : Number: 10
[INFO ] [05-12-06 16:38:34] PMONAPPLI : Connexion de admin sur http://instance10:8080/training1
Exception in thread "Thread-11" java.lang.OutOfMemoryError: Java heap space
[ERROR] [05-12-06 16:39:08] PACEMAKER :
[INFO ] [05-12-06 16:39:08] PACEMAKER : Executé en : 00:00:34
[INFO ] [05-12-06 16:39:08] PACEMAKER : Number: 11
[INFO ] [05-12-06 16:39:09] PMONAPPLI : Connexion de admin sur http://instance11:8080/training2
Exception in thread "Thread-12" java.lang.OutOfMemoryError: Java heap space
[ERROR] [05-12-06 16:39:43] PACEMAKER :
[INFO ] [05-12-06 16:39:43] PACEMAKER : Executé en : 00:00:34
[INFO ] [05-12-06 16:39:43] PACEMAKER : Number: 12
[INFO ] [05-12-06 16:39:44] PMONAPPLI : Connexion de admin sur http://instance12:8080/training3
Exception in thread "Thread-13" java.lang.OutOfMemoryError: Java heap space
[ERROR] [05-12-06 16:40:47] PACEMAKER :
[INFO ] [05-12-06 16:40:47] PACEMAKER : Executé en : 00:01:02
[INFO ] [05-12-06 16:40:47] PACEMAKER : Number: 13
[INFO ] [05-12-06 16:40:48] PMONAPPLI : Connexion de admin sur http://instance13:8080/training4
Exception in thread "Thread-14" java.lang.OutOfMemoryError: Java heap space
[ERROR] [05-12-06 16:41:22] PACEMAKER :
[INFO ] [05-12-06 16:41:22] PACEMAKER : Executé en : 00:00:33
[INFO ] [05-12-06 16:41:22] PACEMAKER : Number: 14
[INFO ] [05-12-06 16:41:23] PMONAPPLI : Connexion de admin sur http://instance14:8080/training5
Exception in thread "Thread-15" java.lang.OutOfMemoryError: Java heap space
[ERROR] [05-12-06 16:41:57] PACEMAKER :
[INFO ] [05-12-06 16:41:57] PACEMAKER : Executé en : 00:00:34
[INFO ] [05-12-06 16:41:57] PACEMAKER : Used Memory: 1013 Mo
[INFO ] [05-12-06 16:41:57] PACEMAKER : Total Memory : 1016 Mo
[INFO ] [05-12-06 16:42:03] PACEMAKER : Used Memory: 1013 Mo
[INFO ] [05-12-06 16:42:03] PACEMAKER : Total Memory : 1016 Mo
[INFO ] [05-12-06 16:42:03] PACEMAKER : Ending Diagnosis
[INFO ] [05-12-06 16:42:03] UTILS : 1624 s
[INFO ] [05-12-06 16:42:03] UTILS : Total Execution Time : 00:27:04
Pour resumer voila mon analyse:

Mes Threads continuent de vivrent et la memoire qu'ils ont bouffé n'est pas restituée...

COmment je libere cette memoire?

Comment liberer de la mémoire non critique?