:writing_hand: This week from me, some tips for ca...
# feed
s
✍️ This week from me, some tips for calling Kotlin suspending functions from Java codebases, using futures, callbacks, and more. https://medium.com/@sam-cooper/call-suspending-kotlin-code-from-java-146efceb2288
h
What about requiring a ExecutorService instead using GlobalScope indirectly, to allow cancellation/scheduling on Java side?
s
Interesting suggestion! I figured the CompletableFuture already has you covered for cancellation, but I can see how it might be useful for the consumer to control other things like thread choice. What did you mean by scheduling?
a
ScheduledThreadPoolExecutor in java
👍 1
s
Nice..so on virtual thread (java 21+) isn’t runBlocking a better /simpler solution?
s
Depends what problem you're trying to solve. When we talk about a thread being blocked we're talking about two problems: 1. The thread is consuming resources/memory but it's not doing any useful work. 2. The thread is prevented from working on other tasks it might be responsible for. Virtual threads can solve the first problem, but they don't address the second. A single virtual thread can still only do one thing at a time. Plenty of the reasons for using coroutines fall into the second category rather than the first. And
runBlocking
itself can cause more problems in that same vein.