I am running a ThreadPoolExecutor program which creates 1000 url and send to executor service.
Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:673)
at java.util.concurrent.ThreadPoolExecutor.addThread(ThreadPoolExecutor.java:681)
at java.util.concurrent.ThreadPoolExecutor.addIfUnderCorePoolSize(ThreadPoolExecutor.java:706)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:650)
at MyProgramName.main(MyProgramName.java:175)
Aug 16, 2014 8:46:20 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {}->MyURLURLURLURLRURL Connection reset
Aug 16, 2014 8:46:20 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {}->MyURLURLURLURLRURL Connection reset
Aug 16, 2014 8:46:20 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {}->MyURLURLURLURLRURL
Aug 16, 2014 8:46:20 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {}->MyURLURLURLURLRURL
2014-08-16 20:46:21.341 java[5100:d07] java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:673)
at sun.awt.AWTAutoShutdown.activateBlockerThread(AWTAutoShutdown.java:312)
at sun.awt.AWTAutoShutdown.setToolkitBusy(AWTAutoShutdown.java:232)
at sun.awt.AWTAutoShutdown.notifyToolkitThreadBusy(AWTAutoShutdown.java:118)
2014-08-16 20:46:21.342 java[5100:d07] (
0 CoreFoundation 0x00007fff9127825c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff9031ce75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff91277e09 -[NSException raise] + 9
3 JavaNativeFoundation 0x000000010c754c3f JNFCallStaticVoidMethod + 213
4 libawt.jnilib 0x0000000115fb8151 setBusy + 53
5 CoreFoundation 0x00007fff911a8d67 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
6 CoreFoundation 0x00007fff911a8cd7 __CFRunLoopDoObservers + 391
7 CoreFoundation 0x00007fff9119a608 __CFRunLoopRun + 1368
8 CoreFoundation 0x00007fff91199e75 CFRunLoopRunSpecific + 309
9 HIToolbox 0x00007fff8fdd9a0d RunCurrentEventLoopInMode + 226
10 HIToolbox 0x00007fff8fdd97b7 ReceiveNextEventCommon + 479
11 HIToolbox 0x00007fff8fdd95bc _BlockUntilNextEventMatchingListInModeWithFilter + 65
12 AppKit 0x00007fff8ac5d24e _DPSNextEvent + 1434
13 AppKit 0x00007fff8ac5c89b -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
14 libawt.jnilib 0x0000000115fb987f -[NSApplicationAWT nextEventMatchingMask:untilDate:inMode:dequeue:] + 124
15 AppKit 0x00007fff8ac5099c -[NSApplication run] + 553
16 libawt.jnilib 0x0000000115fb7f30 +[AWTStarter startAWT:] + 1495
17 libawt.jnilib 0x0000000115fb78aa -[CPerformer perform] + 93
18 Foundation 0x00007fff8c64313e __NSThreadPerformPerform + 229
19 CoreFoundation 0x00007fff911a95b1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
20 CoreFoundation 0x00007fff9119ac62 __CFRunLoopDoSources0 + 242
21 CoreFoundation 0x00007fff9119a3ef __CFRunLoopRun + 831
22 CoreFoundation 0x00007fff91199e75 CFRunLoopRunSpecific + 309
23 java 0x000000010be86843 java + 18499
24 java 0x000000010be8629a java + 17050
25 java 0x000000010be83a98 java + 6808
26 ??? 0x0000000000000005 0x0 + 5
)
Aug 16, 2014 8:46:26 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {}->MyURLURLURLURLRURL Connection reset
Aug 16, 2014 8:46:26 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {}->MyURLURLURLURLRURL
Aug 16, 2014 8:46:26 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {}->MyURLURLURLURLRURL Connection reset
Aug 16, 2014 8:46:26 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {}->MyURLURLURLURLRURL
Aug 16, 2014 8:46:26 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {}->MyURLURLURLURLRURL Connection reset
Aug 16, 2014 8:46:26 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {}->MyURLURLURLURLRURL
Aug 16, 2014 8:46:26 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {}->MyURLURLURLURLRURL Connection reset
Aug 16, 2014 8:46:26 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {}->MyURLURLURLURLRURL Connection reset
Aug 16, 2014 8:46:26 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {}->MyURLURLURLURLRURL
I already made some research in internet and stackoverflow. Some answers say I need to reduce stack size. Some say I need to increase the ulimit using ulimit -a. I am totally confused. I am confused with those answers since they are not specific to ThreadExecutor. Please help me
I run the code in Mac OS, i7 Quad core processor, 16 gb RAM, 1 Tb HD
Code of my program is here in this question Why does the following executor service java Thread program doesn't shut down?