Hacker Newsnew | past | comments | ask | show | jobs | submit | tipsee's commentslogin

I've been working on this since 2017, the last release has been much slower than usual due to changing circumstances in my personal life, so very happy to finally get it out!


Yes :)


If I would be using something like `ctx.result(inputStream)` - would it block the [lightweight] thread until all data is written. Or would the handler return and the data transfer happen in the background?

There is no difference between OS threads and virtual threads in this scenario, and everything in Javalin is blocking (by default).

The `ctx.result()` method doesn't actually write anything directly, it sets a result that will be written later. If you add an "After" handler, this also happens before the request is written. When the request is finally written, it's written on the same thread, and it is a blocking operation.

There is a `RequestLogger` you can hook into that fires after the response has been written.


Thanks! We had some interest in running Javalin on GraalVM in the past, but no one has updated the tutorial in many years. It used to work though, so I bet it still would, if you really wanted it to.


My concern would be around reflection, which I think you said gets used when running with virtual threads? and which native compilation can't handle easily. It may need a Quarkus-like pre-build step to generate glue code to work round it.


are you using an already-existing HTTP engine, like Jetty or Tomcat?

Yes, Javalin is built on top of Jetty.

- how do virtual threads fit into a web framework?

Most JVM web frameworks (Jetty included) have a thread based request lifecyle (one thread handles one request from beginning to end). The java.lang.Threads are extremely expensive (~1mb memory), while Virtual Threads are very cheap (~0mb memory). We also have another ThreadPool for JSON streaming, and one for writing async responses. Using Virtual Threads for these things reduces overall memory pressure.

- do virtual threads make debugging more difficult? (A more general JVM question, I suppose)

Not that I know, but I've never used this in production myself.

- any performance / readability benefit, or just a coolness factor?

The alternative here is java.lang.Threads, so primarily the memory footprint. There is no readability difference. When developing, you don't see this at all.


Thank you! The Vue support is the thing in Javalin I'm the most proud of. There are a hundred web frameworks for the JVM, but none of them have anything close to the Vue support Javalin has. Some people think it's trash, but for me it's perfect.


Not trash at all, thanks for making it.

In general thanks for keeping Javalin simple and opinionated, it is my goto when I get to decide!


> Just a minor nitpick (for those who care about the details of OpenJDK's development): virtual threads are not Project Loom, but rather one of the JEPs contributed to the JDK by Project Loom.

Thanks for clearing that up. Would adding a "from" be sufficient?

and it uses Virtual Threads (“Project Loom”) by default

and it uses Virtual Threads (from “Project Loom”) by default


Yeah, from Project Loom (no need for quotes) would be better, but even the current usage has become colloquial and is okay. :)


Fixed, thank you :)


Rebuild and restart. Javalin itself starts in milliseconds (the test suite starts and stops servers across 600+ tests in less than 10 seconds). If you run in debug mode in IDEA, or use some hot-swapping tool like dcevm or jrebel, you won't always need to restart. I don't think there will ever be a dedicated tool provided by Javalin for this.


I've been dogfooding it hard, which is a great incentive to keep working on it. I think we have 20 Javalin projects where I work. It's also gotten pretty popular lately (3m downloads last 12months), which of course helps a lot :)


It does :)

We use reflection to build the Virtual Thread Factory if the user has Loom enabled in their enviroment: https://github.com/javalin/javalin/blob/master/javalin/src/m...


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: