Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: I finished v5 of a JVM framework I've spent spent half a decade making (javalin.io)
377 points by tipsee on Oct 3, 2022 | hide | past | favorite | 136 comments



I just wanted to say thank you for your work. The straightforward docs are some the best in my opinion when you want to go from "How do I do ..." to answer.

I ended up using Javalin with Kotlin and SQLite to build my wedding website.

Most of my projects are lucky to see the light of day, but with a very persistent project manager and a simple lightweight framework, I was able to ship a fantastic product with very little fuss.


Hey, thank you for using it. Single-page docs are also my favorite, and Javalin/jdbi/SQLite is my goto for quick stuff!

> but with a very persistent project manager

Your partner? :D


Yep! At least they didn't mind when I was drinking on the job.


I can see how DI will be overkill for a wedding website and Javalin/jdbi/sqlite is more than enough but for most business applications written in Java you really wish you had started with DI. Any DI libs you recommend for working with Javalin?


Hard disagree on needing a DI library, manual DI is great.


Disagree on using a lib? cause I guess doing manual DI is still DI.


Yes, disagree on needing a library. The way your comment was worded made it seem to me like you were saying all serious Java applications need a DI library, I'm sorry if I misunderstood you. I prefer doing my ID manually, so no recommendation :)


Could you be more explicit, perhaps with an example? Do you simply mean you prefer function/constructor parameters over DI?


Calling a constructor is DI. ‘new’ is the only DI framework required.

Benefits:

Unbelievably fast startup time

No magic

No annotations, XML or YAML required

No classpath scanning related security vulnerabilities

Conpletely deterministic

In no other language is ‘calling a constructor’ considered so complicated a framework is required.

Try it!


It took me a hot moment to adjust after leaving classic spring Java land to a Scala shop that doesn’t use DI framework, but now I love it. I agree with what you said.

It does help to keep services small so the manual DI arg passing doesn’t get too spread out and boilerplate-y. But I have worked on a dozen services here and don’t miss an automatic DI framework.


> Calling a constructor is DI. ‘new’ is the only DI framework required.

This feels like the sane thing to do, but sadly for historical reasons this won't work with many (if not the most) Java frameworks out there, or even certain options in the .NET ecosystem.

When you get non-trivial frameworks that are deeply entrenched in having DI and using it internally for a bunch of stuff, you'll find yourself out of options, e.g. if you use Spring/Spring Boot.

And in many places something like Spring Boot might be considered an "industry standard" and you might get looked at funny if you suggested using another framework, even more so if they have their own configuration/plugin/utility solutions for it already built within the org.

Personally, however, I rather enjoy alternative takes on how web frameworks could look and even something like Dropwizard/Vert.X/Quarkus have nice quality of life aspects to them.

In a sense, it's nice that the industry is moving towards smaller service based architectures, where you might spin up a new service with whatever tech fits the problem that you're trying to solve, as opposed to being locked into adding code on top of some bloated monolith (though that comes with certain tradeoffs and drawbacks, in regards to complexity and maintenance).


I have a few questions about this approach, cards on the table I mainly deal in C# where DI (through the framework) is the default. How do you manage the initialization of all of the dependencies? Do you need some sort of "root" where everything is initialized and passed in? That was all I could come up with while keeping it testable and that doesn't sound maintainable once you build up the number of dependencies.


I'm also a fan of the manual DI approach - I strongly dislike the magic.

I think it helps if you are building test/fakes of your deps that don't really need as many sub-dependencies. Generally you in a test `@BeforeAll` construct a bunch of objects or for a program you do it in `main`.

I did work on a project while I was at Google that was really big and a decade old that instead had a class with a bunch of lazy getters for each item in the dependency graph, then tests would override or reset the getters with testing versions as needed. It was a little clunky but I preferred that approach over the projects I worked on that used dagger.

If you've read through the Dagger dev-guide [0] there is *a lot* in there, while the manual approach it's usually just `new` which is a really simple concept on it's own :) I think this is the right tradeoff because reading code is harder than writing code, so it's worth the extra setup. In practice I haven't seen it to amount to be an overwhelming amount.

[0]: https://dagger.dev/dev-guide/


What dependencies are multiplying? I organize my code so that the very top level of the api has all external dependencies injected there, there is no public classes below a single exposed class that would need to be directly injected into. The only thing I need to actually inject are things that are outside of my memory space, ie network calls, event buses, dbs. If it's not using something outside of my memory space I am just using new inside my classes, it's far easier to test. For example, if I'm adding a new feature to allow a user to change their address, I would have a single class at the top level "CustomerAddressChange" or whatever. I would inject an interface that wraps everything external, and that is the only thing that anything would be injected into. My tests would all stub only that interface. Everything else is done without any sort of DI container.


When I switched from Java to Go and started doing DI like this, I was amazed at how simple and efficient DI could be. I was taught DI with Spring and never fully grasped why and how it worked. With Go it just clicked and to this day I still have no idea why DI libs are so complicated. If I ever come back to Java, I’ll make sure to do DI manually.


Any DI lib would probably work, it depends on your preferences and use cases though.

I'm personally a fan of Weld since its the reference implementation of the CDI spec.

https://weld.cdi-spec.org/

A friend of mine built an MVC library around Javalin that uses Dagger as the DI container: https://github.com/jehugaleahsa/javalin-mvc


For anyone who wants to get started with this stack you can do `git clone https://gitlab.com/asad-awadia/kotlin-server-app.git` to get a full maven project with javalin, sqlite with ktorm and jdbi everything setup


just wondering, what did you use SQLite for on a wedding website?


Similar to other use cases mentioned already, it was a way for us to create a privacy-focused site to manage guests and give guests the opportunity to update their RSVP, dietary needs, and requested song for the DJ. Additionally there were a few sections of the site where my fiancée could update content as she saw fit by logging in and hitting save. We found the database useful to keep track of RSVPs, gifts, and who we still needed to send thank you's to after the event.

The main drawbacks were people who are not comfortable using the web and people remembering their unique adjective-noun passphrase. Also, I'm not very savvy when it comes to CSS or design so my giddiness was crushed demoing what I thought was the MVP to the "project manager".

I don't want to detract this from being about Javalin though. It's fantastic. I would recommend it and use it again for projects.


Re: pass phrases, my go-to for projects like that is to put a unique hash or something in the URL for each different person. The experience for users is that there's no password to remember or anything like that. They're not going to remember the URL anyway.

You can put the hash in a #xxxx part of the URL so it doesn't show up in logs if thats important to you. The downside is you need to give everyone their own URL (maybe via a QR code on a paper invite). But you already had to give everyone a pass-phrase so whatever :)


It's been SOP for some time (at least 20 years) to use an RDBMS to store your site's content and write a stateless application server to pull data from it and compose a response. Call it the "CMS pattern".

Static site generation, and a few other ideas, challenges this basic pattern, but most of the worlds applications use it. Javelin is trying to make the pattern better on several axes, simplicity first-and-foremost, and not replace it.


I truly mean this with love, but this is the most Java comment I've seen in a long time :-D

And (in the Java/enterprise world) is completely correct.


Funny, I had a LAMP stack in mind while writing it, and more specifically WordPress. For all the enterprise Java webapps out there, I bet there are 1000x more php sites. And they all use the same basic cms pattern.


heh, very good point. WordPress is absolutely everywhere and is exactly this model. I think WordPress forged the path too, so definitely deserves the "blame"


I used PostgreSQL for my wedding website. People could RSVP, say how many were coming, volunteer for support roles since we did too much of it ourselves, etc.

It was overkill and I loved it.


For a website, the question should be why not use SQLite.

Given the various compelling and (by now, here, I hope) well-understood advantages, it should be the default choice. Certainly for a site expecting hits in the mid-hundreds, total. Maybe ten simultaneous connections the day of?


Interesting, I interpreted the question completely differently, i.e. why use database at all?

FWIW, I'm not in the web app world, so my wedding website was a single page HTML; not a single page app, let alone a content management system - I googled something like "Wedding page HTML template", then grabbed a HTML template from w3schools, opened it in notepad, and put my own words and IMG tags. It looked pretty, was "responsive" by default, took very little time to create, and worked solidly.

I'm sufficiently old school / ignorant / pragmatic / lazy / focused / something, to wonder why complicate a wedding page with anything else :-)

(I mean, I'm old and ignorant and simple enough that I keep misinterpreting what "static site generator" is :P )


Interesting, I interpreted the question completely differently, i.e. why use database at all?

Maybe the wedding page has forms, needs to store data and author is most familiar with Java or maybe they are getting creative and are calling third party services for convenience, lots of reasons. A simpler solution could be nginx/cgi and a local file for the DB, or cloudfare workers(you can render HTML from them) and their key/value storage.


Yeah that was what I meant but everyone else seems to be commenting except the person I was replying to lol. I am not attacking databases I am just wondering what they used it for on a wedding website.


"Because my website is just pages and doesn't need a database" is a perfectly good reason not to use SQLite, sure.

OP can reply why a database was useful for his wedding site, if he wants; I can think of some reasons why it might be.


This looks great! I did Java professionally for years but when all the jobs moved to EE I bailed for Ruby/Rails and similar. Java the language I've always really enjoyed. It's the frameworks and hundreds of design patterns that repelled me. I felt like they were all needlessly complex. If frameworks like this one were more common in Java world, I may never have left.

This looks really nice! I wish more Java devs approached things with KISS and simple in mind, rather than looking at every problem as a way to apply some obscure design pattern that involves 15 levels of abstraction and indirection for a relatively simple microservice.


I just started using this! Spring Boot seemed so convoluted, having to go to a website to even begin. And then to have the Tomcat dependency seemed like a heavy lift just to get a "hello world" working. Virtual threads seems to be the way to go.

Virtual threads in Java 19: https://www.infoq.com/articles/java-virtual-threads/


Excellent resource on virtual thread by one of the authors! Thanks.

I have to see I’m pleased to see Java moving fast those days.

I’m still digesting 17 and 18, but that give me a reason to look at 19.

I honestly project loom was far from reaching that level of “standardness” … so I haven’t looked into it in years


Related:

Show HN: Javalin 1.0 – A Kotlin/Java web framework - https://news.ycombinator.com/item?id=15644430 - Nov 2017 (87 comments)

Show HN: Javalin, a Java/Kotlin REST API Framework - https://news.ycombinator.com/item?id=14434089 - May 2017 (21 comments)


The good old days!


Congratulations! This is great!

Java deserves its comeback among the wave of nu-programming we are going through.


> Java deserves its comeback among the wave of nu-programming we are going through.

What is nu-programming? And why would Java deserve a comeback?


>nu-programming

I made that one up.

>And why would Java deserve a comeback?

Java is an extremely mature piece of technology, and having used it on the enterprise, I can attest that few things come close on flexibility and stability. Also, functional languages on top of the JVM (clojure, kotlin, scala) are very interesting on their own. Java deserves some love from this new wave of paradigm changes like "write-once-run-anywhere" v2.0, monadic programming, serverless functions, etc...


> Java is an extremely mature piece of technology, and having used it on the enterprise, I can attest that few things come close on flexibility and stability.

Very much agreed, as long as you don't have to deal with legacy projects with Java 8 to Java 11 migration, which might sour the view of the language as a whole for some folks. I think Java doesn't get as much love nowadays due to some of the frameworks having to deal with historical baggage (e.g. Spring being unwieldy, which is at least partially why people prefer Spring Boot), though Java probably isn't the only language for which this is the case: https://earthly.dev/blog/brown-green-language/

That said, Java and .NET are both good options in my eyes - reasonably productive, with pretty decent type systems and good runtime performance. Not perfect, but almost always decent choices. Oh, and the runtimes themselves are pretty great, especially because we get languages like Kotlin, Scala for the JVM and F# for the CLR.

Then again, for different use cases I wouldn't scoff at Python, Ruby or Node either. Even something like PHP can be passable in some cases.


you can also use it with kotlin


I successfully used Javalin in a project using Kotlin + Koin for dependency injection + jOOQ for database access. Was a joy to setup and work in that project.

Thank you!

Congratulations on the major release and keep up the good work.


JDBI also could be really nice as a minimalistic layer for a db access


Congrats on the release! I reviewed Javalin lately and it was high on my list. We use quite a bit of Kotlin and look for a framework. I really dislike the magic that annotations bring to most popular Java frameworks (and Hibernate). I prefer most is just code". Kotlin helped us a lot in making our code more type safe, especially the KProperty way of referring to methods made a difference.

Though I ended up leaning towards KTor, with Javalin as a close second.

How would anyone with more knowledge compare the two (Javalin and KTor)?


> ...would anyone with more knowledge compare the two (Javalin and KTor)?

I'd love to hear more on this as well. While I've done some minor stuff with Ktor, because JetBrains, I too would love some insight related to these as well.


Javalin is the bomb! I don’t know why Java community likes to make things complicated.


“An idiot admires complexity, a genius admires simplicity, a physicist tries to make it simple, for an idiot anything the more complicated it is the more he will admire it, if you make something so clusterfucked he can't understand it he's gonna think you're a god cause you made it so complicated nobody can understand it. That's how they write journals in Academics, they try to make it so complicated people think you're a genius.” - Terry A. Davis


Would prefer if this were worded more simply.


I mean, you see who it’s attributed to…


I like Jetty. Javalin is nice for Kotlin but Jetty + java has worked well for me.


What do you use for routing and DI? do you use Jetty handlers or the servlet API?


Dropwizard is cool if you write REST microservices. It uses embedded jetty, JAX-RS, Jackson, metrics, etc.

As far as I know it's inspiration for Spring Boot, and it's simpler and ready to use on production.


Very nice!

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. There are two in JDK 19 (425 and 428), another in advanced stages (429), and there will probably be more. OpenJDK Projects aren't features but teams working on producing features focused on some area and then offering them to the JDK.


> 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 :)


Well done! Can't wait to see Loom become the default for web frameworks.

Also spotted the Vue plugin - great to see this as so many light weight web apps with a few pages can benefit from using Vue but setting up all the build chain is such a drama that it's usually not worth it. Look forward to trying it out.


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!


This is Javalin and it is great. We switched to it a few months ago from another micro-framework.


Indeed it is! May I asked what you switched from?


I'll guess and say Spark.

Not the big data Spark. This one: sparkjava.com

A nice piece of work in its own right.


You guessed correctly!

Spark was fine, but was abandoned. Which means it was stuck using an end-of-life’d version of Jetty. Which meant that we could no longer pass security audits.

Whereas Javalin continues to get frequently updated.


Spark ruined me. Everyone expects Spring, but dealing with Spring and all the pointless annotation magic is a misery; I find myself longing to just use Spark and forgo all that crap.

I suppose I'll try Javalin then next time I have the choice.


> Spark was fine, but was abandoned.

Aw, that's sad to hear. I've been out of JVM-in-anger space for awhile, but I always liked Spark when I was.


Curious as to what has kept you motivated to continue working on the project this long? So many open source developers don't last nearly as long or jump to something new once the novelty of the project wears off.


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 :)


Looks interesting!

One question about the response methods: 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?

One use-case I've only see marginally addressed in some frameworks is being able to run code past the point where all data is written - e.g. to record logs and metrics around the outcome of a request - e.g. whether the client hung up or all data was stored in socket buffers. If sending the result "blocks", that kind of code can be added naturally with a try/finally block around it.

As far as I understand the docs, it might not block, but one might be able to install an "After" handler? Or would that also only run before the response is actually sent?


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.


Before I saw the site, I just saw the headline and thought, "Another one I might look at, after I do something serious in Javalin".


Some quick questions: - are you using an already-existing HTTP engine, like Jetty or Tomcat?

- how do virtual threads fit into a web framework?

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

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


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.


Nothing to do with the project, but I read through it, so...

1. It's built natively on Jetty - very tight integration, not just some libs running in a Jetty container.

2. Web is inherently Request/Response - all of this can be handled with dramatically less resource requirements using Virtual Threads. Web is sort of the absolutely-best-use-case for Virtual Threads where as a Game Engine would be the opposite of that (one critical rendering thread and MAYBE a few extra long-lived threads for processing physics, audio, etc.)

3. I haven't tried debugging a Loom project but it's been in incubation for just under 100 years so I have to imagine this has been figured out.

4. About twice the throughput and 1/2 the latency of full OS threads - https://github.com/ebarlas/project-loom-comparison


I usted Javalin a few months ago for a kotlin api. It's awesome!


I have used Javalin for a number of Kotlin backend projects of late, thanks for all your hard work!


I find that hello world example very pleasant to look at. Love that it's effectively a one-liner.

    public static void main(String[] args) {
        var app = Javalin.create(/*config*/)
            .get("/", ctx -> ctx.result("Hello World"))
            .start(7070);
    }


Looks very similar to Express.js which came out in 2011 and has been one of the most popular frameworks in the Node.js world.

https://expressjs.com/en/starter/hello-world.html


I haven’t written Java or Kotlin in years but this makes me want to try it again. Nice work!


Great work. It's fascinating to see how "modern" Java looks these days.


Java always was fine for those of us who refused to get suckered into the j2ee/ejb vortex of nonsense.


I was sucked into Java EE. Still got the battle scars to prove it. Trench warfare mostly, wallowing through mud.


Javalin is also super good at serving content via a web API, too. To external clients or within a bigger app. I wonder how Loom will speed up concurrent calls to my APIs served by Javalin.


Javalin is a great name!


this is very cool. quick question though - do u have a gradle build setup ? im new to java and saw this problem on spring boot. That you needed to have this bunch of complex directory structures cos of the way java packages worked. for e.g. the test directories were parallel to the src directory, so they could be named with the same package name.

for a single file...i can just run java. but it would be nice to see a gradle setup that keeps simplicity and yet can have thousands of files and testcases organised in a nice structure.

secondly, it is nice that you have Jetty hooks. Can you also have CORS & proxy protocol ? its literally mandatory to have this stuff if ur deploying on any of the k8s based clouds.

e.g. https://stackoverflow.com/questions/73225314/accept-proxy-pr...


That's not a spring thing, but a java tools convention (having a src and test folder etc). Nothing stops you from doing it differently, but most tools work out of the box if you follow that setup. So better to just do it than having to fight with / configure every part of your pipeline.


im not disputing that. im wondering if javalin came with one out-of-the-box is all.


I'm not super sure what you're asking, but Javalin doesn't care at all about your directory structure. You can add it as a dependency to any existing gradle project you have, and import it like any other Java library (like java.lang.String).


Looks nice. Does it support hot reload? We use Quarkus heavily at work and one of the nifty feature is its ability to hot reload (fast restart to be specific) within few millisec, which makes our development quite a joy, kind of spoiled by that to be honest. If not now, any plan to support it in future?


That's probably the first time I see a java web framework api that actually makes me want to try it.


From my understanding this framework doesn’t include an ORM. I consider the ORM one of the most important component for a web framework


How does the dev tooling work? Rebuild & restart the app each time? I find working on any sizable codebase this can take minutes even on the latest spring-boot. Quakrus has an interesting live reloading classloader.


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.


If you use IDEA you can right-click modified .java file and click 'Compile and Reload File' https://www.jetbrains.com/help/idea/altering-the-program-s-e...


How does Javalin compare with Dropwizard which is also quite lightweight?


Javalin offers way less, it's more or less just the web routing layer. No databases, no ORM, no config loading, etc.


Javalin is great and a worthy successor to its predecessor Sparkjava


What happened to sparkjava?

Edit: looks like its alive and kicking : https://sparkjava.com/news


i'm using javalin in production without problems. i have a custom html templating engine and can't wait to try the virtual threads.

had no problems at all. i really like it. thanks!


I haven’t tried this framework, but just looking at some examples, the web sockets and sse seem a bit out of place. In a Loom world you’d expect these to use channels or queues or something similar in a loop - not callbacks. Callback hell is what virtual threads try to avoid. I’m not sure if loom has any primitives like go’s multi-channel select that might make this workable though.

In either case Loom and frameworks that use it are super exciting! I’m looking forward to removing the 20 different thread pools we need to avoid deadlocks and just using the common one in our Clojure apps.


Having recently implemented a WebSocket service in Go, the Javalin way seems preferable. This is what a similar Go version would look like:

    wsHandler := func(w http.ResponseWriter, r \*http.Request) {
        conn, err := upgrader.Upgrade(w, r)
        if err != nil {
            w.SendStatus(http.StatusInternalServerError)
            return
        }

        ctx, ctxCancel := context.WithCancel(context.Background())
        var wg sync.WaitGroup

        wg.Add(1)
        go func() {
            defer sync.Done()

            for {
                msg, err := conn.ReadMessage()
                if err != nil {
                    return
                }
            }
        }()

        msgPipe := make(chan []byte, 1024)
        wg.Add(1)
        go func() {
            defer wg.Done()
            for {
                select {
                case <-ctx.Done():
                    return
                case msg := <- msgPipe
                    if err := conn.WriteMessage(msg); err != nil { return }
                }
            }
        }()

        go func() {
            <- ctx.Done()
            wg.Wait()
            close(msgPipe)
        }()
    }
I like Go, but I found writing WebSocket code very annoying.


We don't have selectable channels yet, but they're not needed as much in Java as they are in Go, because often multiple channels are used to signal cancellation, whereas in Java there's a standard mechanism for cancellation (Thread.interrupt() at the low level, with Future.cancel being higher level, and JEP 428's structured concurrency being higher level still https://openjdk.org/jeps/428).


Congrats on v5.

Have you tried it yet with GraalVM and native compilation?

Any gotchas?


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.


Javalin is amazing.

Kudos.


Javalin has been powering one of my projects for years now without issues. Really great framework. Thanks!


I'm pretty sure the "Hello Javalin World" Kotlin example won't compile, just FYI.


Seems to compile fine here, what's the issue?

Edit: I was looking at the wrong snippet, the offending snippet has been fixed.


Probably not used to seeing lambdas inside of parens:

  .get("/", ctx -> ctx.result("Hello World"))
Could also be written as

  .get("/") { ctx -> ctx.result("Hello World") }
The second form seems much more common in Kotlin.


Yeah, no, he was 100% correct, I was just looking at the wrong snippet. It's been fixed now :)


Huh, I wonder what's different with my setup. I would need to put curly braces around that closure before it would compile, i.e:

    .get("/", { ctx -> ctx.result("Hello World") })
Closures defined only by the arrow are a Java thing... or so I thought. :D


> Closures defined only by the arrow are a Java thing... or so I thought. :D

In fairness, I think you did copy the Java version. There's a little switch in the code boxes where you can toggle the language, if you switch to Kotlin you get the version with trailing closures :)

Edit: I'm an idiot, I see the snippet you mean now. It's been updated now, give it a minute.


Sweet, thanks!


It looks inspired by express.js, is it the case or are they both inspired by an older framework?


Express is inspired by Connect JS in terms of middleware — middleware written for Connect works in Express. The middleware style I believe is originally inspired by Rack, a Ruby project.

Sinatra, also Ruby, predates Express and is based on Rack (in a similar way to Express, which used to be based on Connect if I’m not mistaken).

I’m not sure what inspired Sinatra, but that’s probably the influence you’re seeing in these frameworks.


Both inspired by Sinatra, the OG :)


Given Project Loom hasn't been available, how does it utilise Virtual Threads already?


If you run this on JDK19 with *--enable-preview*, Javalin will use Virtual Threads for the Server ThreadPool (as well as all other ThreadPools it has).


How does it compare to coroutines in Kotlin?


I mean, it sort of doesn't? Coroutines is a whole concept, Virtual Threads can in most cases just replace java.lang.Threads, which is how it's implemented in Javalin. We just swap out the OS Threads for Virtual Threads.


i'd be interested in this too. my guess: virtual threads are slightly more memory efficient and slightly faster, but same ballpark.


now that i think about it i'm pretty sure my guess is completely wrong. memory usage (and thus concurrent-inactives) might be similar, but i expect the virtual threads to be much more efficient.


except if you use the appropriate non-blocking methods! with blocking io, kotlin coroutines are just running in a thread pool.


Project Loom is in preview, and far from available. As far as I can see, Javalin doesn't make use of virtual threads yet.


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...


Virtual threads are already available in the current version of the JDK (19) as a Preview feature. Because it's not a preview language feature but a preview API, libraries can use it without compiling with --enable-preview, either with reflection or by having the application supply a virtual thread ThreadFactory, which means they can make use of virtual threads if the application turns preview features on.

Preview language features are different as they require compiling with --enable-preview, which creates a "poisoned" class file that cannot be loaded at all without preview enabled, so preview language features are not recommended for use by libraries, but preview APIs are fine (see JEP 12: Preview Features https://openjdk.org/jeps/12).


Did half a decade sound more impressive than 5 years?


Yes :)


Can we use this to render traditional apps (no js frameworks)?


Absolutely!


Excellent thank you! Which template engines are supported?



heard great things about Javalin and I'm curious to check it out. congrats!


On twentieth of a century !!


Peeking int the docs, it reminds me a little bit of Vert-X. What do you think qbout such a statement?


I respect Vert.x a lot, so I'm flattered, but Vert.x is a huge beast with focus on performance. Javalin is basically a tiny UX layer on top of Jetty. I don't think they are very similar frameworks. Javalin's focus is on being "good enough" all around, but with the best possible developer experience.


doesn't JVM sniff of the 00's?




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

Search: