On a quite old jsch release (0.1.55), we could see lots of blocked threads in multi-thread environment.
This is due to the fact that Channel is using a Vector for its internal pool.
The issue is still there on master, so I have prepared a merge-request, pending your review and approval.
Note1: The code change was tested fine in lab and production (on top of 0.1.55).
The suggested code change had to manage this new line (not present in 0.1.55):
index &= Integer.MAX_VALUE;
which was introduced recently with 793753a
So it required some specific change to be thread-safe (and not tested in production).
Note2: After code change on top of 0.1.55, it was observed no more slowness or blocked threads
Here are the same observed stack-traces (every minute) showing the blocked thread when calling Channel.getChannel:
Stack 4 - Mar 05 05:54:01
"Connect thread X.X.X.X session" #2631 prio=5 os_prio=64 tid=0x0000000106346800 nid=0xa51 waiting for monitor entry [0xfffffffe31bfe000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.jcraft.jsch.Channel.getChannel(Channel.java:83)
- waiting to lock <0x00000004e52a0168> (a java.util.Vector)
at com.jcraft.jsch.Session.run(Session.java:1448)
at java.lang.Thread.run(Thread.java:745)
Stack 5 - Mar 05 05:55:00
"Connect thread X.X.X.X session" #2631 prio=5 os_prio=64 tid=0x0000000106346800 nid=0xa51 waiting for monitor entry [0xfffffffe31bfe000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.jcraft.jsch.Channel.getChannel(Channel.java:83)
- waiting to lock <0x00000004e52a0168> (a java.util.Vector)
at com.jcraft.jsch.Session.run(Session.java:1448)
at java.lang.Thread.run(Thread.java:745)
Stack 6 - Mar 05 05:56:00
"Connect thread X.X.X.X session" #2631 prio=5 os_prio=64 tid=0x0000000106346800 nid=0xa51 waiting for monitor entry [0xfffffffe31bfe000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.jcraft.jsch.Channel.getChannel(Channel.java:83)
- waiting to lock <0x00000004e52a0168> (a java.util.Vector)
at com.jcraft.jsch.Session.run(Session.java:1448)
at java.lang.Thread.run(Thread.java:745)
Stack 7 - Mar 05 05:57:01
"Connect thread X.X.X.X session" #2631 prio=5 os_prio=64 tid=0x0000000106346800 nid=0xa51 waiting for monitor entry [0xfffffffe31bfe000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.jcraft.jsch.Channel.getChannel(Channel.java:83)
- waiting to lock <0x00000004e52a0168> (a java.util.Vector)
at com.jcraft.jsch.Session.run(Session.java:1448)
at java.lang.Thread.run(Thread.java:745)
Stack 8 - Mar 05 05:58:00
"Connect thread X.X.X.X session" #2631 prio=5 os_prio=64 tid=0x0000000106346800 nid=0xa51 waiting for monitor entry [0xfffffffe31bfe000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.jcraft.jsch.Channel.getChannel(Channel.java:83)
- waiting to lock <0x00000004e52a0168> (a java.util.Vector)
at com.jcraft.jsch.Session.run(Session.java:1448)
at java.lang.Thread.run(Thread.java:745)
[...]
Stack 28 - Mar 05 06:18:00
"Connect thread X.X.X.X session" #2631 prio=5 os_prio=64 tid=0x0000000106346800 nid=0xa51 waiting for monitor entry [0xfffffffe31bfe000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.jcraft.jsch.Channel.getChannel(Channel.java:83)
- waiting to lock <0x00000004d6640128> (a java.util.Vector)
at com.jcraft.jsch.Session.run(Session.java:1448)
at java.lang.Thread.run(Thread.java:745)
On a quite old jsch release (0.1.55), we could see lots of blocked threads in multi-thread environment.
This is due to the fact that Channel is using a Vector for its internal pool.
The issue is still there on master, so I have prepared a merge-request, pending your review and approval.
Note1: The code change was tested fine in lab and production (on top of 0.1.55).
The suggested code change had to manage this new line (not present in 0.1.55):
index &= Integer.MAX_VALUE;
which was introduced recently with 793753a
So it required some specific change to be thread-safe (and not tested in production).
Note2: After code change on top of 0.1.55, it was observed no more slowness or blocked threads
Here are the same observed stack-traces (every minute) showing the blocked thread when calling Channel.getChannel:
Stack 4 - Mar 05 05:54:01
"Connect thread X.X.X.X session" #2631 prio=5 os_prio=64 tid=0x0000000106346800 nid=0xa51 waiting for monitor entry [0xfffffffe31bfe000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.jcraft.jsch.Channel.getChannel(Channel.java:83)
- waiting to lock <0x00000004e52a0168> (a java.util.Vector)
at com.jcraft.jsch.Session.run(Session.java:1448)
at java.lang.Thread.run(Thread.java:745)
Stack 5 - Mar 05 05:55:00
"Connect thread X.X.X.X session" #2631 prio=5 os_prio=64 tid=0x0000000106346800 nid=0xa51 waiting for monitor entry [0xfffffffe31bfe000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.jcraft.jsch.Channel.getChannel(Channel.java:83)
- waiting to lock <0x00000004e52a0168> (a java.util.Vector)
at com.jcraft.jsch.Session.run(Session.java:1448)
at java.lang.Thread.run(Thread.java:745)
Stack 6 - Mar 05 05:56:00
"Connect thread X.X.X.X session" #2631 prio=5 os_prio=64 tid=0x0000000106346800 nid=0xa51 waiting for monitor entry [0xfffffffe31bfe000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.jcraft.jsch.Channel.getChannel(Channel.java:83)
- waiting to lock <0x00000004e52a0168> (a java.util.Vector)
at com.jcraft.jsch.Session.run(Session.java:1448)
at java.lang.Thread.run(Thread.java:745)
Stack 7 - Mar 05 05:57:01
"Connect thread X.X.X.X session" #2631 prio=5 os_prio=64 tid=0x0000000106346800 nid=0xa51 waiting for monitor entry [0xfffffffe31bfe000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.jcraft.jsch.Channel.getChannel(Channel.java:83)
- waiting to lock <0x00000004e52a0168> (a java.util.Vector)
at com.jcraft.jsch.Session.run(Session.java:1448)
at java.lang.Thread.run(Thread.java:745)
Stack 8 - Mar 05 05:58:00
"Connect thread X.X.X.X session" #2631 prio=5 os_prio=64 tid=0x0000000106346800 nid=0xa51 waiting for monitor entry [0xfffffffe31bfe000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.jcraft.jsch.Channel.getChannel(Channel.java:83)
- waiting to lock <0x00000004e52a0168> (a java.util.Vector)
at com.jcraft.jsch.Session.run(Session.java:1448)
at java.lang.Thread.run(Thread.java:745)
[...]
Stack 28 - Mar 05 06:18:00
"Connect thread X.X.X.X session" #2631 prio=5 os_prio=64 tid=0x0000000106346800 nid=0xa51 waiting for monitor entry [0xfffffffe31bfe000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.jcraft.jsch.Channel.getChannel(Channel.java:83)
- waiting to lock <0x00000004d6640128> (a java.util.Vector)
at com.jcraft.jsch.Session.run(Session.java:1448)
at java.lang.Thread.run(Thread.java:745)