Skip to content

Commit 65bb77a

Browse files
committed
1
1 parent bad6f84 commit 65bb77a

File tree

2 files changed

+146
-108
lines changed

2 files changed

+146
-108
lines changed

rxlib/src/main/java/org/rx/spring/MxController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ Object invoke(HttpServletRequest request) {
183183
JSONObject params = getParams(request);
184184
Class<?> kls = Class.forName(params.getString("bean"));
185185
Object bean = SpringContext.getBean(kls);
186-
Method method = Reflects.getMethodMap(kls).get(params.getString("method")).first();
187186
List<Object> args = params.getJSONArray("args");
187+
Method method = Reflects.getMethodMap(kls).get(params.getString("method")).where(p -> p.getParameterCount() == args.size()).first();
188188
Class<?>[] parameterTypes = method.getParameterTypes();
189189
Object[] a = Linq.from(method.getGenericParameterTypes()).select((p, i) -> {
190190
Object o = args.get(i);

rxlib/src/test/java/org/rx/core/TestCore.java

+145-107
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.alibaba.fastjson2.JSON;
44
import com.alibaba.fastjson2.TypeReference;
5+
import io.netty.util.concurrent.FastThreadLocal;
56
import lombok.Data;
67
import lombok.SneakyThrows;
78
import lombok.extern.slf4j.Slf4j;
@@ -39,6 +40,7 @@
3940
import java.util.*;
4041
import java.util.concurrent.*;
4142
import java.util.concurrent.atomic.AtomicInteger;
43+
import java.util.stream.Collectors;
4244

4345
import static org.rx.bean.$.$;
4446
import static org.rx.core.Extends.*;
@@ -231,114 +233,150 @@ public void inheritThreadLocal() {
231233
ThreadPool.endTrace();
232234
sleep(5000);
233235
System.out.println("---next---");
234-
//
235-
// //CompletableFuture.xxAsync异步方法正确获取trace
236-
// ThreadPool.startTrace(null);
237-
// for (int i = 0; i < 2; i++) {
238-
// int finalI = i;
239-
// CompletableFuture<Void> cf1 = pool.runAsync(() -> {
240-
// log.info("TRACE ASYNC-1 {}", finalI);
241-
// pool.runAsync(() -> {
242-
// log.info("TRACE ASYNC-1_1 {}", finalI);
243-
// sleep(oneSecond);
244-
// }).whenCompleteAsync((r, e) -> log.info("TRACE ASYNC-1_1 uni {}", r));
245-
// sleep(oneSecond);
246-
// }).whenCompleteAsync((r, e) -> log.info("TRACE ASYNC-1 uni {}", r));
247-
// log.info("TRACE ASYNC MAIN {}", finalI);
248-
// CompletableFuture<Void> cf2 = pool.runAsync(() -> {
249-
// log.info("TRACE ASYNC-2 {}", finalI);
250-
// sleep(oneSecond);
251-
// }).whenCompleteAsync((r, e) -> log.info("TRACE ASYNC-2 uni {}", r));
252-
// }
253-
// ThreadPool.endTrace();
254-
//
255-
// ThreadPool.startTrace(null);
256-
// log.info("TRACE ALL_OF start");
257-
// CompletableFuture.allOf(pool.runAsync(() -> {
258-
// log.info("TRACE ALL_OF ASYNC-1");
259-
// pool.runAsync(() -> {
260-
// log.info("TRACE ALL_OF ASYNC-1_1");
261-
// sleep(oneSecond);
262-
// }).whenCompleteAsync((r, e) -> log.info("TRACE ALL_OF ASYNC-1_1 uni {}", r));
263-
// sleep(oneSecond);
264-
// }).whenCompleteAsync((r, e) -> log.info("TRACE ALL_OF ASYNC-1 uni {}", r)), pool.runAsync(() -> {
265-
// log.info("TRACE ALL_OF ASYNC-2");
266-
// sleep(oneSecond);
267-
// }).whenCompleteAsync((r, e) -> log.info("TRACE ALL_OF ASYNC-2 uni {}", r))).whenCompleteAsync((r, e) -> {
268-
// log.info("TRACE ALL-OF {}", r);
269-
// }).get(10, TimeUnit.SECONDS);
270-
// log.info("TRACE ALL_OF end");
271-
// ThreadPool.endTrace();
272-
// sleep(5000);
273-
// System.out.println("---next---");
274-
//
275-
// //parallelStream
276-
// ThreadPool.startTrace(null);
277-
// Arrays.toList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).parallelStream().map(p -> {
278-
// //todo
279-
// Arrays.toList("a", "b", "c").parallelStream().map(x -> {
280-
// log.info("parallelStream {} -> {}", p, x);
281-
// return x.toString();
282-
// }).collect(Collectors.toList());
283-
// log.info("parallelStream {}", p);
284-
// return p.toString();
285-
// }).collect(Collectors.toList());
286-
// ThreadPool.endTrace();
287-
//
288-
// //timer
289-
// ThreadPool.startTrace(null);
290-
// Tasks.timer().setTimeout(() -> {
291-
// log.info("TIMER 1");
292-
// pool.run(() -> {
293-
// log.info("TIMER 2");
294-
// });
295-
// }, d -> d > 5000 ? -1 : Math.max(d * 2, 1000), null, TimeoutFlag.PERIOD.flags());
296-
// ThreadPool.endTrace();
297-
// sleep(8000);
298-
//
299-
// //netty FastThreadLocal 支持继承
300-
// FastThreadLocal<Integer> ftl = new FastThreadLocal<>();
301-
// ftl.set(64);
302-
// pool.run(() -> {
303-
// assert ftl.get() == 64;
304-
// log.info("Inherit ok 1");
305-
// }, null, RunFlag.INHERIT_FAST_THREAD_LOCALS.flags());
306-
//
307-
// pool.runAsync(() -> {
308-
// assert ftl.get() == 64;
309-
// log.info("Inherit ok 2");
310-
// }, null, RunFlag.INHERIT_FAST_THREAD_LOCALS.flags());
311-
// sleep(2000);
312-
//
313-
// log.info("--ExecutorService--");
314-
// ThreadPool.startTrace(null);
315-
//// ExecutorService es = pool;
316-
//// es.submit(() -> {
317-
//// log.info("submit..");
318-
//// return 1024;
319-
//// });
320-
//// es.execute(() -> {
321-
//// log.info("exec..");
322-
//// });
323-
//// sleep(1000);
324-
//
325-
// log.info("test scope1 start");
326-
// ThreadPool.startTrace("newScope1", true);
327-
// log.info("test scope2 start");
328-
//
329-
// ThreadPool.startTrace("newScope2", true);
330-
// log.info("test scope3");
331-
// ThreadPool.endTrace();
332-
//
333-
// log.info("test scope2 end");
334-
// ThreadPool.endTrace();
335-
//
336-
// log.info("test scope1 end");
337-
// ThreadPool.endTrace();
338-
// log.info("--done--");
339236

340-
// log.info("--TestService--");
341-
// ThreadPool.startTrace(null);
237+
//CompletableFuture.xxAsync异步方法正确获取trace
238+
ThreadPool.startTrace(null);
239+
for (int i = 0; i < 2; i++) {
240+
int finalI = i;
241+
CompletableFuture<Void> cf1 = pool.runAsync(() -> {
242+
log.info("TRACE ASYNC-1 {}", finalI);
243+
pool.runAsync(() -> {
244+
log.info("TRACE ASYNC-1_1 {}", finalI);
245+
sleep(oneSecond);
246+
}).whenCompleteAsync((r, e) -> log.info("TRACE ASYNC-1_1 uni {}", r));
247+
sleep(oneSecond);
248+
}).whenCompleteAsync((r, e) -> log.info("TRACE ASYNC-1 uni {}", r));
249+
log.info("TRACE ASYNC MAIN {}", finalI);
250+
CompletableFuture<Void> cf2 = pool.runAsync(() -> {
251+
log.info("TRACE ASYNC-2 {}", finalI);
252+
sleep(oneSecond);
253+
}).whenCompleteAsync((r, e) -> log.info("TRACE ASYNC-2 uni {}", r));
254+
}
255+
ThreadPool.endTrace();
256+
sleep(5000);
257+
System.out.println("---next---");
258+
259+
ThreadPool.startTrace(null);
260+
log.info("TRACE ALL_OF start");
261+
CompletableFuture.allOf(pool.runAsync(() -> {
262+
log.info("TRACE ALL_OF ASYNC-1");
263+
pool.runAsync(() -> {
264+
log.info("TRACE ALL_OF ASYNC-1_1");
265+
sleep(oneSecond);
266+
}).whenCompleteAsync((r, e) -> log.info("TRACE ALL_OF ASYNC-1_1 uni {}", r));
267+
sleep(oneSecond);
268+
}).whenCompleteAsync((r, e) -> log.info("TRACE ALL_OF ASYNC-1 uni {}", r)), pool.runAsync(() -> {
269+
log.info("TRACE ALL_OF ASYNC-2");
270+
sleep(oneSecond);
271+
}).whenCompleteAsync((r, e) -> log.info("TRACE ALL_OF ASYNC-2 uni {}", r))).whenCompleteAsync((r, e) -> {
272+
log.info("TRACE ALL-OF {}", r);
273+
}).get(10, TimeUnit.SECONDS);
274+
log.info("TRACE ALL_OF end");
275+
ThreadPool.endTrace();
276+
sleep(5000);
277+
System.out.println("---next---");
278+
279+
//parallelStream
280+
ThreadPool.startTrace(null);
281+
Arrays.toList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).parallelStream().map(p -> {
282+
//todo
283+
Arrays.toList("a", "b", "c").parallelStream().map(x -> {
284+
log.info("parallelStream {} -> {}", p, x);
285+
return x.toString();
286+
}).collect(Collectors.toList());
287+
log.info("parallelStream {}", p);
288+
return p.toString();
289+
}).collect(Collectors.toList());
290+
ThreadPool.endTrace();
291+
sleep(5000);
292+
System.out.println("---next---");
293+
294+
//timer
295+
ThreadPool.startTrace(null);
296+
Tasks.timer().setTimeout(() -> {
297+
log.info("TIMER 1");
298+
pool.run(() -> {
299+
log.info("TIMER 2");
300+
});
301+
}, d -> d > 5000 ? -1 : Math.max(d * 2, 1000), null, TimeoutFlag.PERIOD.flags());
302+
ThreadPool.endTrace();
303+
sleep(8000);
304+
System.out.println("---next---");
305+
306+
//netty FastThreadLocal 支持继承
307+
FastThreadLocal<Integer> ftl = new FastThreadLocal<>();
308+
ftl.set(64);
309+
pool.run(() -> {
310+
assert ftl.get() == 64;
311+
log.info("Inherit ok 1");
312+
}, null, RunFlag.INHERIT_FAST_THREAD_LOCALS.flags());
313+
314+
pool.runAsync(() -> {
315+
assert ftl.get() == 64;
316+
log.info("Inherit ok 2");
317+
}, null, RunFlag.INHERIT_FAST_THREAD_LOCALS.flags());
318+
sleep(2000);
319+
System.out.println("---next---");
320+
321+
//ExecutorService
322+
ThreadPool.startTrace(null);
323+
log.info("root scope begin");
324+
ExecutorService es = pool;
325+
es.submit(() -> {
326+
log.info("submit..");
327+
return 1024;
328+
});
329+
es.execute(() -> {
330+
log.info("exec..");
331+
});
332+
sleep(1000);
333+
334+
//nest trace
335+
log.info("nest scope1 prepare");
336+
ThreadPool.startTrace("newScope1", true);
337+
log.info("nest scope1 begin");
338+
339+
log.info("nest scope2 prepare");
340+
ThreadPool.startTrace("newScope2", true);
341+
log.info("nest scope2 begin");
342+
343+
es.execute(() -> {
344+
log.info("nest sub begin");
345+
for (int i = 0; i < 5; i++) {
346+
ThreadPool.startTrace(null);
347+
log.info("nest sub {}", i);
348+
ThreadPool.endTrace();
349+
}
350+
log.info("nest sub end");
351+
});
352+
353+
log.info("nest scope2 end");
354+
ThreadPool.endTrace();
355+
log.info("nest scope2 post");
356+
357+
log.info("nest scope1 end");
358+
ThreadPool.endTrace();
359+
log.info("nest scope1 post");
360+
361+
log.info("root scope end");
362+
ThreadPool.endTrace();
363+
log.info("--done--");
364+
365+
for (int i = 0; i < 3; i++) {
366+
int finalI = i;
367+
es.execute(() -> {
368+
log.info("nest sub{} begin", finalI);
369+
for (int j = 0; j < 5; j++) {
370+
ThreadPool.startTrace(null);
371+
log.info("nest sub{} {}", finalI, j);
372+
sleep(200);
373+
ThreadPool.endTrace();
374+
}
375+
log.info("nest sub{} end", finalI);
376+
});
377+
}
378+
sleep(5000);
379+
System.out.println("---done---");
342380
}
343381

344382
@SneakyThrows

0 commit comments

Comments
 (0)