Many threads creation by SyncIdleConnectionMonitorThread
See original GitHub issueI have to work with a large number of Unirest instances and I had a problem of creating new threads.
The problem is the kong.unirest.apache.SyncIdleConnectionMonitorThread
class.
For each instance of Uniest, a new thread of this class is created.
And in my case, jvm crashes after creating ~ 16kk threads.
To fix this problem, I think need to use thread pools.
For example, Executors.newCachedThreadPool ()
.
Of course I close all instances. At the same time, usually no more than 1k instances work.
I understand that problem is quite specific 😃
=>0x00000000819cf000 JavaThread "Thread-16135980" daemon [_thread_in_vm, id=636100, stack(0x000000007f0d0000,0x000000007f1d0000)]
Register to memory mapping:
RAX=0x000000007f1cc2c0 is pointing into the stack for thread: 0x00000000819cf000
RBX=0x0000000000000004 is an unknown value
RCX=0x0000000000003000 is an unknown value
RDX=0x0000000000000006 is an unknown value
RSP=0x000000007f1cf2c0 is pointing into the stack for thread: 0x00000000819cf000
RBP=0x0000000000000000 is an unknown value
RSI=0x000000007f1cf2c0 is pointing into the stack for thread: 0x00000000819cf000
RDI=0x0000000000000004 is an unknown value
R8 =0x0000000000000006 is an unknown value
R9 =0x000000003b702f50 is an unknown value
R10={method} {0x000000004d7eccf8} 'run' '()V' in 'kong/unirest/apache/SyncIdleConnectionMonitorThread'
R11=0x000000007f0da170 is pointing into the stack for thread: 0x00000000819cf000
R12=0x000000003b702f50 is an unknown value
R13=0x00000000819cf000 is a thread
R14=0x000000007f1cf388 is pointing into the stack for thread: 0x00000000819cf000
R15={method} {0x000000004d7eccf8} 'run' '()V' in 'kong/unirest/apache/SyncIdleConnectionMonitorThread'
Stack: [0x000000007f0d0000,0x000000007f1d0000], sp=0x000000007f1cf2c0, free space=1020k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top Results From Across the Web
Unirest Thread Leak - java - Stack Overflow
I have taken a thread dump and a lot of these threads are waiting on com.mashape.unirest.http.utils.SyncIdleConnectionMonitorThread as shown ...
Read more >How Many Threads Can a Java VM Support? - Baeldung
A quick and practical overview of how many threads can JVM create.
Read more >Creating Threads and Multithreading in Java - DZone
Here's a brief introduction to Java Thread concepts that many people find tricky like multithreading and concurrency.
Read more >Multithreading Concepts
When the number of threads in a process is less than or equal to the number ... Creating a thread is less expensive...
Read more >Know Creating Threads and Multithreading in Java - Edureka
Unlike many other computer languages, Java provides built-in support for multithreaded programming. A multithreaded program contains two or more ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can certainly populate Unirest with your own configured instance of Apache Http Client that doesn’t use a threadmonitor and has whatever you need as far as cookies go:
https://github.com/Kong/unirest-java/blob/master/unirest/src/test/java/BehaviorTests/CustomClientTest.java#L57-L81
At first I thought: “What can I change if the client is created immediately, when building the config”. And then I checked - a very interesting solution, building a client on demand.
Well then you can consider the problem settled. Thanks for the help.