loom ea based jdk18 feedback
dreamlike_ocean lei
dreamlike.vertx at gmail.com
Wed Nov 17 11:13:15 UTC 2021
1, continuation api
If the low-level continuation api can be exposed, then in reactive
programming, asynchronous operations can be simplified like this
val scope = ContinuationScope("vertx")
fun launch(runnable: Runnable){
Continuation(scope){
runnable.run()
}.run()
}
fun <T> Future<T>.getAwait():T{
val c = Continuation.getCurrentContinuation(scope)?: throw
IllegalStateException()
onComplete {
c.run()
}
Continuation.yield(scope)
if (succeeded()){
return result()
}else{
throw cause()
}
}
In fact, this code works very well on the loom ea built on jdk17
But on the loom ea built on jdk18, due to the migration of this api from
java.lang to jdk.internal.vm, I cannot access this api, and this code
cannot improve the asynchronous operation well.
Loom Proposal.md (java.net)
<https://cr.openjdk.java.net/~rpressler/loom/Loom-Proposal.html> mentioned
"The motivation for adding continuations to the Java platform is for the
implementation of fibers, but continuations have some other interesting
uses, and so it is a secondary goal of this project to provide
continuations as a public API"
I really hope I can directly access this api in the future version
1.
Virtual thread custom scheduler
The loom ea built on jdk17 allows the scheduler of the virtual thread to be
specified in this way, which can help us bridge the world of nio and bio in
the netty-based reactive framework
Thread.ofVirtual().scheduler(eventloop()).start()
However, the loom ea built on jdk18 removed this api, which resulted in me
having to use the default scheduler (fork/join pool) to schedule, and then
submit it to the evenltoop task queue. This is an avoidable cross Thread
overhead.
I hope you can consider reopening the api of the custom scheduler in the
future version
translated by Google translate
More information about the loom-dev
mailing list