我想使用Java流执行以下操作:
我有一个Map<Enum, List<A>>,我想将它转化到List<B>哪里B都有属性Enum, A.
因此,对于该键列表中的每个键和每个项目,我需要创建一个项目B并将所有项目收集到一个项目中List<B>.
如何使用Java流完成?
谢谢!
Spring Boot 执行器指标 ( /actuator/metrics) 带有许多默认指标。他们之中有一些是:
"jvm.memory.max",
"jvm.threads.states",
"process.files.max",
"jvm.gc.memory.promoted",
"tomcat.servlet.error",
"system.load.average.1m",
"jvm.memory.used",
"jvm.gc.max.data.size",
"jvm.memory.committed",
"http.server.requests",
"system.cpu.count",
"logback.events",
"tomcat.global.sent",
...
Run Code Online (Sandbox Code Playgroud)
是否可以只曝光其中的几个?(即过滤它们或更好的是,告诉 Spring boot 根本不要收集它们?)
我有一个会发出一些Date. 这Date映射到我在某些Executer.
我想做的是等待所有 1024 个 HTTP 请求,然后再发出下一个Date.
目前运行时,onNext()被调用多次,然后稳定在某个稳定的速率。
我怎样才能改变这种行为?
PS 如果需要的话,我愿意改变架构。
private void run() throws Exception {
Executor executor = Executors.newFixedThreadPool(2);
Flux<Date> source = Flux.generate(emitter ->
emitter.next(new Date())
);
source
.log()
.limitRate(1)
.doOnNext(date -> System.out.println("on next: " + date))
.map(date -> Flux.range(0, 1024))
.flatMap(i -> Mono.fromCallable(Pipeline::simulateHttp)
.subscribeOn(Schedulers.fromExecutor(executor)))
.subscribe(s -> System.out.println(s));
Thread.currentThread().join();
}
Run Code Online (Sandbox Code Playgroud)
HTTP请求模拟:
private static String simulateHttp() {
try {
System.out.println("start http call");
Thread.sleep(3_000);
} catch (Exception e) {}
return …Run Code Online (Sandbox Code Playgroud) 假设我有一个Grid<Person>和一些person.getStatus()返回一个枚举
enum Status {
SINGLE, MARRIED, DIVORCED
}
Run Code Online (Sandbox Code Playgroud)
我想根据此枚举的值为网格的列着色。
怎么做到呢?
考虑以下示例:
public static void main(String[] args) {
Function<String, Integer> f1 = str -> str.length();
f1.andThen(i -> {
System.out.println("length is " + i);
return "why do I need to return a String here?";
}).apply("12345");
}
Run Code Online (Sandbox Code Playgroud)
我试图理解为什么我必须返回String。
这背后的逻辑是什么?我希望这andThen会接受Consumer<Integer>让我们说或类似的东西。
那么为什么andThen()要求我返回原始输入的类型呢?