2016-12-07 10:34:41 -08:00
|
|
|
// lowlevel/ThreadSize.java
|
2016-12-30 17:23:13 -08:00
|
|
|
// (c)2017 MindView LLC: see Copyright.txt
|
2016-07-05 14:46:09 -06:00
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
2016-09-23 13:23:35 -06:00
|
|
|
// Visit http://OnJava8.com for more book information.
|
2017-05-17 21:38:05 -06:00
|
|
|
// {ExcludeFromGradle} Takes a long time or hangs
|
2016-07-05 14:46:09 -06:00
|
|
|
import java.util.concurrent.*;
|
2016-12-21 11:06:49 -08:00
|
|
|
import onjava.Nap;
|
2016-07-05 14:46:09 -06:00
|
|
|
|
|
|
|
public class ThreadSize {
|
|
|
|
static class Dummy extends Thread {
|
|
|
|
@Override
|
2017-01-22 16:48:11 -08:00
|
|
|
public void run() { new Nap(1); }
|
2016-07-05 14:46:09 -06:00
|
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
|
|
ExecutorService exec =
|
|
|
|
Executors.newCachedThreadPool();
|
|
|
|
int count = 0;
|
|
|
|
try {
|
|
|
|
while(true) {
|
|
|
|
exec.execute(new Dummy());
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
} catch(Error e) {
|
|
|
|
System.out.println(
|
|
|
|
e.getClass().getSimpleName() + ": " + count);
|
|
|
|
System.exit(0);
|
2016-12-04 12:15:21 -08:00
|
|
|
} finally {
|
|
|
|
exec.shutdown();
|
2016-07-05 14:46:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|