You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MemoryHog.java 627B

123456789101112131415161718
  1. import java.util.concurrent.ExecutionException;
  2. import java.util.concurrent.ExecutorService;
  3. import java.util.concurrent.Future;
  4. public class MemoryHog {
  5. final ExecutorService taskManager;
  6. // Use 128 MB of data, then run with -Xmx1G for 10 threads or -Xmx512M for 5 threads
  7. final byte[] someBigData = new byte[1024 * 1024 * 128];
  8. public MemoryHog(final ExecutorService executorService) {
  9. taskManager = executorService;
  10. }
  11. public void doSomething() throws ExecutionException, InterruptedException {
  12. Future<?> future = taskManager.submit(() -> System.out.println("Executing task"));
  13. future.get();
  14. }
  15. }