Earlier quoted context omitted.
It’s a thread that supports n virtual threads. You want synchronized in virtual thread a and not the carrier thread which will block all the virtual threads. Been away from Java land for a while. How did something like that even get into release? That’s like a pretty big loaded shotgun to leave lying around with lots of kids playing, no?
It's an explicitly documented shortcoming of the existing implementation that will be fixed soon. I knew immediately from the title of TA what probably happened. The other similar limitations (CPU-bound tasks, native calls) seem much more severe, but are ultimately unsolvable. Meanwhile, the issue with synchronized is regarded as a scalability bottleneck since the JDK is supposed to temporarily spawn additional platf…
We switched to Java 21 virtual threads and got a deadlock in TPC-C for Postgres
251–253 of 253 posts
Re: We switched to Java 21 virtual threads and got a deadlock in TPC-C for Postgres
#252Re: We switched to Java 21 virtual threads and got a deadlock in TPC-C for Postgres
#253Why synchronized block are not preemptible? When compiling public void syncMethod() { synchronized(lock) { // some code } } they could translate to public void syncMethod() { await reentrantLockAsync.lockAsync(); try { await somecodeAsync(); } finally { await lock.unlockAsync() } }
The first issue is your second code is not Java (no await/async literal for Java yet) The second issue is they're not completely equivalent. In the second case, you'd need extra memory for the `reentrantLock`, while `synchronized` works with any object. Furthermore, if you need to use `wait/notify`, then there need to be an extra `Condition` object to use in combination with the `ReentrantLock`. For sure, developers…
C# introduced:
await foreach (int item in RangeAsync(10, 3))
Console.Write(item + " "); // Prints 10 11 12
So you dont have to type:IAsyncEnumerator e = RangeAsync(10, 3).GetAsyncEnumerator();
try {
while (await e.MoveNextAsync()) Console.Write(e.Current + " ");
} finally {
if (e != null) await e.DisposeAsync();
}