Lines 37-42
Link Here
|
37 |
*/ |
37 |
*/ |
38 |
public class MemoryUsage extends TestCase { |
38 |
public class MemoryUsage extends TestCase { |
39 |
private static final int NUM_COLUMNS = 255; |
39 |
private static final int NUM_COLUMNS = 255; |
|
|
40 |
|
41 |
private static void printMemoryUsage(String msg) { |
42 |
System.out.println(" Memory (" + msg + "): " + Runtime.getRuntime().totalMemory()/(1024*1024) + "MB"); |
43 |
} |
40 |
|
44 |
|
41 |
/** |
45 |
/** |
42 |
* Generate a spreadsheet until OutOfMemoryError |
46 |
* Generate a spreadsheet until OutOfMemoryError |
Lines 50-56
Link Here
|
50 |
public static void mixedSpreadsheet(Workbook wb, int numCols){ |
54 |
public static void mixedSpreadsheet(Workbook wb, int numCols){ |
51 |
|
55 |
|
52 |
System.out.println("Testing " + wb.getClass().getName()); |
56 |
System.out.println("Testing " + wb.getClass().getName()); |
53 |
System.out.println("Memory: " + Runtime.getRuntime().totalMemory()/(1024*1024) + "MB"); |
57 |
printMemoryUsage("before"); |
54 |
int i=0, cnt=0; |
58 |
int i=0, cnt=0; |
55 |
try { |
59 |
try { |
56 |
Sheet sh = wb.createSheet(); |
60 |
Sheet sh = wb.createSheet(); |
Lines 65-72
Link Here
|
65 |
} |
69 |
} |
66 |
} catch (OutOfMemoryError er){ |
70 |
} catch (OutOfMemoryError er){ |
67 |
System.out.println("Failed at row=" + i + ", objects : " + cnt); |
71 |
System.out.println("Failed at row=" + i + ", objects : " + cnt); |
|
|
72 |
} catch (final Exception e) { |
73 |
System.out.println("Unable to reach an OutOfMemoryError"); |
74 |
System.out.println(e.getClass().getName() + ": " + e.getMessage()); |
68 |
} |
75 |
} |
69 |
System.out.println("Memory: " + Runtime.getRuntime().totalMemory()/(1024*1024) + "MB"); |
76 |
printMemoryUsage("after"); |
70 |
} |
77 |
} |
71 |
|
78 |
|
72 |
/** |
79 |
/** |
Lines 74-80
Link Here
|
74 |
* The data is generated until OutOfMemoryError. |
81 |
* The data is generated until OutOfMemoryError. |
75 |
* <p> |
82 |
* <p> |
76 |
* as compared to {@link #mixedSpreadsheet(org.apache.poi.ss.usermodel.Workbook, int)}, |
83 |
* as compared to {@link #mixedSpreadsheet(org.apache.poi.ss.usermodel.Workbook, int)}, |
77 |
* this method does not set string values and, hence, does not invole the Shared Strings Table. |
84 |
* this method does not set string values and, hence, does not involve the Shared Strings Table. |
78 |
* </p> |
85 |
* </p> |
79 |
* |
86 |
* |
80 |
* @param wb the workbook to write to |
87 |
* @param wb the workbook to write to |
Lines 83-89
Link Here
|
83 |
public static void numberSpreadsheet(Workbook wb, int numCols){ |
90 |
public static void numberSpreadsheet(Workbook wb, int numCols){ |
84 |
|
91 |
|
85 |
System.out.println("Testing " + wb.getClass().getName()); |
92 |
System.out.println("Testing " + wb.getClass().getName()); |
86 |
System.out.println("Memory: " + Runtime.getRuntime().totalMemory()/(1024*1024) + "MB"); |
93 |
printMemoryUsage("before"); |
87 |
int i=0, cnt=0; |
94 |
int i=0, cnt=0; |
88 |
try { |
95 |
try { |
89 |
Sheet sh = wb.createSheet(); |
96 |
Sheet sh = wb.createSheet(); |
Lines 97-104
Link Here
|
97 |
} |
104 |
} |
98 |
} catch (OutOfMemoryError er){ |
105 |
} catch (OutOfMemoryError er){ |
99 |
System.out.println("Failed at row=" + i + ", objects : " + cnt); |
106 |
System.out.println("Failed at row=" + i + ", objects : " + cnt); |
|
|
107 |
} catch (final Exception e) { |
108 |
System.out.println("Unable to reach an OutOfMemoryError"); |
109 |
System.out.println(e.getClass().getName() + ": " + e.getMessage()); |
100 |
} |
110 |
} |
101 |
System.out.println("Memory: " + Runtime.getRuntime().totalMemory()/(1024*1024) + "MB"); |
111 |
printMemoryUsage("after"); |
102 |
} |
112 |
} |
103 |
|
113 |
|
104 |
/** |
114 |
/** |
Lines 111-117
Link Here
|
111 |
*/ |
121 |
*/ |
112 |
public static void xmlBeans(int numCols) { |
122 |
public static void xmlBeans(int numCols) { |
113 |
int i = 0, cnt = 0; |
123 |
int i = 0, cnt = 0; |
114 |
System.out.println("Memory: " + Runtime.getRuntime().totalMemory() / (1024 * 1024) + "MB"); |
124 |
printMemoryUsage("before"); |
115 |
|
125 |
|
116 |
CTWorksheet sh = CTWorksheet.Factory.newInstance(); |
126 |
CTWorksheet sh = CTWorksheet.Factory.newInstance(); |
117 |
CTSheetData data = sh.addNewSheetData(); |
127 |
CTSheetData data = sh.addNewSheetData(); |
Lines 128-135
Link Here
|
128 |
} |
138 |
} |
129 |
} catch (OutOfMemoryError er) { |
139 |
} catch (OutOfMemoryError er) { |
130 |
System.out.println("Failed at row=" + i + ", objects: " + cnt); |
140 |
System.out.println("Failed at row=" + i + ", objects: " + cnt); |
|
|
141 |
} catch (final Exception e) { |
142 |
System.out.println("Unable to reach an OutOfMemoryError"); |
143 |
System.out.println(e.getClass().getName() + ": " + e.getMessage()); |
131 |
} |
144 |
} |
132 |
System.out.println("Memory: " + Runtime.getRuntime().totalMemory() / (1024 * 1024) + "MB"); |
145 |
printMemoryUsage("after"); |
133 |
} |
146 |
} |
134 |
|
147 |
|
135 |
/** |
148 |
/** |
Lines 149-165
Link Here
|
149 |
} |
162 |
} |
150 |
} catch (OutOfMemoryError er) { |
163 |
} catch (OutOfMemoryError er) { |
151 |
System.out.println("Failed at row=" + i); |
164 |
System.out.println("Failed at row=" + i); |
|
|
165 |
} catch (final Exception e) { |
166 |
System.out.println("Unable to reach an OutOfMemoryError"); |
167 |
System.out.println(e.getClass().getName() + ": " + e.getMessage()); |
152 |
} |
168 |
} |
153 |
System.out.println("Memory: " + Runtime.getRuntime().totalMemory() / (1024 * 1024) + "MB"); |
169 |
printMemoryUsage("after"); |
154 |
} |
170 |
} |
155 |
|
171 |
|
156 |
/** |
172 |
/** |
157 |
* Generate atatched (having a parent bean) Xml beans until OutOfMemoryError. |
173 |
* Generate attached (having a parent bean) Xml beans until OutOfMemoryError. |
158 |
* This is MUCH more memory-efficient than {@link #testXmlDetached()} |
174 |
* This is MUCH more memory-efficient than {@link #testXmlDetached()} |
159 |
* |
175 |
* |
160 |
* @see #testXmlAttached() |
176 |
* @see #testXmlAttached() |
161 |
*/ |
177 |
*/ |
162 |
public void testXmlAttached(){ |
178 |
public void testXmlAttached(){ |
|
|
179 |
printMemoryUsage("before"); |
163 |
List<CTRow> rows = new ArrayList<CTRow>(); |
180 |
List<CTRow> rows = new ArrayList<CTRow>(); |
164 |
int i = 0; |
181 |
int i = 0; |
165 |
//top-level element in sheet.xml |
182 |
//top-level element in sheet.xml |
Lines 174-181
Link Here
|
174 |
} |
191 |
} |
175 |
} catch (OutOfMemoryError er) { |
192 |
} catch (OutOfMemoryError er) { |
176 |
System.out.println("Failed at row=" + i); |
193 |
System.out.println("Failed at row=" + i); |
|
|
194 |
} catch (final Exception e) { |
195 |
System.out.println("Unable to reach an OutOfMemoryError"); |
196 |
System.out.println(e.getClass().getName() + ": " + e.getMessage()); |
177 |
} |
197 |
} |
178 |
System.out.println("Memory: " + Runtime.getRuntime().totalMemory() / (1024 * 1024) + "MB"); |
198 |
printMemoryUsage("after"); |
179 |
} |
199 |
} |
180 |
|
200 |
|
181 |
public void testMixedHSSF(){ |
201 |
public void testMixedHSSF(){ |