Live data from Hacker News

Java Virtual Threads Preview

openjdk.java.net

191–200 of 270 posts

Re: Java Virtual Threads Preview

#191
post #112

A key point that I was particularly happy about is that ThreadLocals work well with virtual threads. My personal killer application: MDC for logging. I have just tried to build proper logging into a Javascript/Typescript application and none of the logging frameworks support MDC (or need cumbersome workarounds) because the async-isms in the underlying language prevent it from working as intended.

Thread locals work, but we think in scope locals we have a better more robust mechanism more suited to the way thread locals are used in things like logging libraries.

Re: Java Virtual Threads Preview

#192
post #45

Earlier quoted context omitted.

I'd love to know who, of those pinned to an LTS release, has actually made use of a support contract with a company providing contracted support for an LTS release, whether it's Oracle or another company. I don't doubt they exist, but I have no idea what that support even looks like. My team has been happily tracking the twice-yearly JDK bumps. We started development three years ago against Java 8 and made a series o…

I am not on a support contract (rather the opposite: small team). But I am just being careful to get caught having to spend time upgrading code that I would otherwise not have touched, just because my non-LTS JVM runs out of support. Support is not just a support contract, but also security patches being released. In my understanding, for non-LTS versions that ceases quickly when the next version is out. Particularly…

With the new oracle licensing you can use an LTS until the next LTS comes out and one additional year on top, for free. That one year should be more than enough for testing, isn’t it? Especially that thanks to strong encapsulations java updates are even more of a breeze.

Re: Java Virtual Threads Preview

#193

I'm curious about > There are situations when the VM cannot suspend a virtual thread, in which case it is said to be pinned. Currently, there are two: > When a native method is currently executing in the virtual thread (even if it is calling back into Java) Does that mean any kind of native code is currently paying some extra cost due to the possibility of being blocking? What if I e.g. want to call a library that is…

You aren’t incurring any overhead because that native code isn’t going to try and yield execution. You would only incur the overhead if the code called back to Java, and then that Java code performed some blocking operation.

Re: Java Virtual Threads Preview

#194

There is a spectrum of solutions for dealing with slow I/O in programming languages (well, all I/O is best assumed to be slow I/O). At the two ends of the spectrum are: - continuation-passing style (CPS), hand-coded or compiler - preemptive threading / processes In between lie various solutions, like async/await (closer to CPS), and green threads (closer to preemptive threading). The key difference between the two en…

> Any solution towards the thread side of the spectrum will yield significantly larger memory footprints than solutions towards the CPS side of the spectrum.

The community-at-large decided that hand-tuning garbage collection was too finicky and not worth it, even though it obviously 'costs' memory.

I'm frankly at a loss as to why so, so, so many blogposts and tech experts are all-in on the CPS-side of this argument; it seems quite obvious to me that in the vast majority of cases, the considerably simpler* model of (green) threads means you're making the exact same trade-off: Simpler to write and debug code at the cost of needing more memory when running the app you write.

*) For sequential/imperative-style languages, that is. If you're writing in a language that is definitely and clearly intended to be written in a functional style, I can see how the gap between CPS-style and threading-style is far narrower. However, java, python, javascript - these are languages where the significant majority of lines of code written are sequential and imperative in nature.

Also note that in e.g. java you can actually configure stack sizes as you make threads. Thus, your choice of words of "'significantly' more memory footprint" is debatable.

Re: Java Virtual Threads Preview

#195
post #137

Is Virtual Threads part of Project Loom? i.e We expect Project Loom to land a little bit after this or are they completely separate issues and Project Loom is still far from landing?

JEPs are the mechanism by which projects deliver changes. This, and two other JEPs form the bulk of the work done as part of Loom, along with a number of other connected JEPs mentioned in this one.

Re: Java Virtual Threads Preview

#196
post #118
post #87

Earlier quoted context omitted.

Javalin is _very_ lightweight, and starts up fast. Use the framework that best suits your requirements. Also, Java is working on reducing ram usage: https://openjdk.java.net/projects/lilliput/

there's Helidon: https://helidon.io/ as well from Oracle. though at the moment, I'm using Javalin.

I thought so too. And wrote simple web service using Helidon SE. It eats 300+ MB of RAM. I spend some time trying to optimize GC and all that stuff. Similar node service would eat 30 MB of RAM.

May be Graal would save us all. Until then Java is beyond salvation.

Re: Java Virtual Threads Preview

#198
post #171

Earlier quoted context omitted.

I prefer Kotlin for a number of reasons but still use Java heavily as it's still a better choice in many places. I think this will be of massive benefit to both languages. Kotlin coroutines will probably be mostly relegated to multiplatform and JS backends but that is fine, server side Kotlin will take full advantage of virtual threads. :D

Where is Java a better choice than Kotlin?

So the main thing is libraries. If you write your library in Kotlin then it depends on the Kotlin runtime JARs which seriously bloats it's dependencies. Not a problem where the library is only applicable in Kotlin-land but if it's generally useful from Java/Clojure/Scala then it's better to write it in Java.

The other case is general OSS software, Java reaches a wider audience in my field (distributed databases, streaming data, etc). Java is pretty much considered the lingua-franca of Big Data with some very small Scala footprint and much less fluency in Kotlin.

I generally write all my own stuff ontop of these on Kotlin but drop down into Java where I need to be able to share things.

Re: Java Virtual Threads Preview

#199
post #177

Earlier quoted context omitted.

If you use gargantuan Java frameworks, you'll use a lot of RAM. Just don't do that. With Spring Boot and similar frameworks, the RAM usage is really just very modest. I'll give you startup times, since I am not a believer in Quarkus and Graal. And I wouldn't use Java for a serverless function that needs to spin up and respond quickly. But for a typical (blue/green-deployed) application in my world, startup time is st…

I had a Quarkus server app start up in 0.1s the other week. And BTW Spring Boot does native compilation now too [1] Your "belief" is putting you at risk of ignoring a wide range of Java use cases unnecessarily. [1] https://docs.spring.io/spring-native/docs/current/reference/...

You are probably right. It's one of those things where I've not seen a need to jump aboard. I'm still being fearful of reflection going to break on me. Probably irrational fear, but fed by me not understanding how it wouldn't break. Which I should study up on. Which I don't, since I don't have the need. And here I am ... vicious circle.

Re: Java Virtual Threads Preview

#200

Earlier quoted context omitted.

If you use gargantuan Java frameworks, you'll use a lot of RAM. Just don't do that. With Spring Boot and similar frameworks, the RAM usage is really just very modest. I'll give you startup times, since I am not a believer in Quarkus and Graal. And I wouldn't use Java for a serverless function that needs to spin up and respond quickly. But for a typical (blue/green-deployed) application in my world, startup time is st…

Care to share more thoughts on Quarkus? I'm evaluating it for an upcoming app. From my limited reading it can be used with and without Graal.

See my sibling comment: my fears are irrational.
Post reply on HN