1 /*
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
164
165 public AllocationThread(int id, long amount) {
166 super("Thread " + id);
167 threadId = id;
168 amountOfGarbage = amount;
169 garbage = new LinkedList<>();
170 }
171
172 /**
173 * Returns list of garbage.
174 * @return List with thread garbage.
175 */
176 public List<Object> getList(){
177 return garbage;
178 }
179
180 @Override
181 public void run() {
182 System.out.println("Start the thread " + threadId);
183 while (TestStressIHOPMultiThread.this.isRunning()) {
184 allocate(amountOfGarbage);
185 free();
186 }
187 }
188
189 private void silentJoin() {
190 System.out.println("Join the thread " + threadId);
191 try {
192 join();
193 } catch (InterruptedException ie) {
194 throw new RuntimeException(ie);
195 }
196 }
197
198 /**
199 * Allocates thread local garbage
200 */
201 private void allocate(long amount) {
202 long allocated = 0;
203 while (allocated < amount && TestStressIHOPMultiThread.this.isRunning()) {
204 garbage.add(new byte[CHUNK_SIZE]);
|
1 /*
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
164
165 public AllocationThread(int id, long amount) {
166 super("Thread " + id);
167 threadId = id;
168 amountOfGarbage = amount;
169 garbage = new LinkedList<>();
170 }
171
172 /**
173 * Returns list of garbage.
174 * @return List with thread garbage.
175 */
176 public List<Object> getList(){
177 return garbage;
178 }
179
180 @Override
181 public void run() {
182 System.out.println("Start the thread " + threadId);
183 while (TestStressIHOPMultiThread.this.isRunning()) {
184 try {
185 allocate(amountOfGarbage);
186 } catch (OutOfMemoryError e) {
187 free();
188 System.out.println("OutOfMemoryError occurred in thread " + threadId);
189 break;
190 }
191 free();
192 }
193 }
194
195 private void silentJoin() {
196 System.out.println("Join the thread " + threadId);
197 try {
198 join();
199 } catch (InterruptedException ie) {
200 throw new RuntimeException(ie);
201 }
202 }
203
204 /**
205 * Allocates thread local garbage
206 */
207 private void allocate(long amount) {
208 long allocated = 0;
209 while (allocated < amount && TestStressIHOPMultiThread.this.isRunning()) {
210 garbage.add(new byte[CHUNK_SIZE]);
|