trace cross thread
There are some other ways to trace cross thread except the methods in Tracer
.
- usage 1.
@TraceCrossThread
public static class MyCallable<String> implements Callable<String> {
@Override
public String call() throws Exception {
return null;
}
}
...
ExecutorService executorService = Executors.newFixedThreadPool(1);
executorService.submit(new MyCallable());
- usage 2.
ExecutorService executorService = Executors.newFixedThreadPool(1);
executorService.submit(CallableWrapper.of(new Callable<String>() {
@Override public String call() throws Exception {
return null;
}
}));
or
ExecutorService executorService = Executors.newFixedThreadPool(1);
executorService.execute(RunnableWrapper.of(new Runnable() {
@Override public void run() {
//your code
}
}));
- usage 3.
@TraceCrossThread
public class MySupplier<String> implements Supplier<String> {
@Override
public String get() {
return null;
}
}
...
CompletableFuture.supplyAsync(new MySupplier<String>());
or
CompletableFuture.supplyAsync(SupplierWrapper.of(()->{
return "SupplierWrapper";
})).thenAccept(System.out::println);
- usage 4.
CompletableFuture.supplyAsync(SupplierWrapper.of(() -> {
return "SupplierWrapper";
})).thenAcceptAsync(ConsumerWrapper.of(c -> {
// your code visit(url)
System.out.println("ConsumerWrapper");
}));
or
CompletableFuture.supplyAsync(SupplierWrapper.of(() -> {
return "SupplierWrapper";
})).thenApplyAsync(FunctionWrapper.of(f -> {
// your code visit(url)
return "FunctionWrapper";
}));
Sample codes only