virtual thread 真是讓人興奮
所以 jdbc driver 都不用改自動就會變 virtual thread ?
web request ->
socket virtual thread -> (virtually blocking)
business logic ->
jdbc request ->
driver socket virtual thread -> (virtually blocking)
然後在兩次的 virtual block 中,背後 OS thread 可能已經換過,或是沒變這樣?
web request virtual thread->
socket -> (virtually blocking)
business logic ->
jdbc request -> driver socket -> (virtually blocking)
除非是為了 structured concurrency,不然可以不用再自己看到一層 virtual thread?
等等來看看他的 EA 能不能玩
比較在意 ThreadLocal 關聯的應用場景..
var oldValue = myTL.get();
myTL.set(newValue);
try {
...
} finally {
myTL.set(oldValue);
}
Without this imposed structure, when a thread is shared among multiple tasks, one task’s TL values might leak into another. Virtual threads solve that problem by being lightweight enough to not require sharing.
沒看懂,為何 lightweight 就不用 sharing.
他是說以前一定要寫 finally 去回溯/移除 自己放在 ThreadLocal 的變數,因為 Thread 多半有 pool,是大家共用的。
之後用 virtual thread 就沒人在共用了,所以 ThreadLocal 不用怕碰到別人塞的值,也不用 finally 去處理。
而你講的 sharing 是該 thread 被用的當下,很多人都想塞變數,這個的確沒變,要靠 Scope Variable 的結構減少忘記互蓋的問題。
阿對齁,他必須得讓 ThreadLocal 在 virtual thread 中行為像之前一樣,了解了。
Even basic control flow, like loops and try/catch, need to be reconstructed in “reactive” DSLs, some sporting classes with hundreds of methods.
RxJava 就是你
一個 class 有上百個 method 就是錯錯錯,沒什麼好說的
能夠寫正常的程式的話,誰要寫 reactive,誰要寫 async/await
Project Loom 走在正確的道路上,成功後就會換其他平台來學