source: trunk/org.etsi.common/src/org/etsi/common/MemoryTest.java @ 53

Last change on this file since 53 was 50, checked in by phdmakk, 13 years ago
  • adjusted result one step down to avoid borderline case crashes
  • Property svn:mime-type set to text/plain
File size: 1.2 KB
Line 
1package org.etsi.common;
2
3import java.io.BufferedReader;
4import java.io.InputStreamReader;
5
6public class MemoryTest {
7
8        public static void main(String[] args) {
9                try {
10                        int heap = 512;
11                        int heapIncrement = 128;
12                        while(startSecondJVM(heap+heapIncrement)==0){
13                                heap+=heapIncrement;
14                        }
15                        System.out.println(heap-2*heapIncrement);
16                } catch (Exception e) {
17                        // TODO Auto-generated catch block
18                        e.printStackTrace();
19                }
20        }
21        public static int startSecondJVM(int heap) throws Exception {
22            String separator = System.getProperty("file.separator");
23            String classpath = System.getProperty("java.class.path");
24            String path = System.getProperty("java.home")
25                    + separator + "bin" + separator + "java";
26            ProcessBuilder processBuilder =
27                    new ProcessBuilder(path, "-Xmx"+heap+"m", "-Xss128m", "-cp",
28                    classpath,
29                    MemoryTestDummy.class.getName());
30            Process process = processBuilder.start();
31            process.waitFor();
32//          BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
33//          String line;
34//          while((line = br.readLine())!=null){
35//              System.out.println(":"+line);
36//          }
37            process.destroy();
38            return process.exitValue();
39        }
40}
Note: See TracBrowser for help on using the repository browser.