Introduction about Quarkus

Today, developing and deploying applications to the Cloud is no longer a strange thing. We don’t need to worry much about the infrastructure to deploy the application, everything Cloud Providers has already installed, we just focus on developing the application.

The trend of deploying applications on the Cloud is how to be scalable, in short, we can deploy an application with a load balancer, which can handle a large number of requests from users at the same time. To do this, our deployment strategy must accommodate that the number of instances of the application can increase or decrease based on the traffic to the application and also, when starting a new instance to handle user requests, the fastest start time is possible.

For scripting languages ​​like JavaScript, PHP, or Python, when starting a new instance of the application, they can almost immediately handle requests from users. But with Java, applications need start time to handle requests.

Understanding those limitations, there are many new Java frameworks and libraries introduced to solve this start time problem, aiming to help us develop Cloud Native applications with Java. One of them is Quarkus, a Supersonic Subatomic Java, optimized to run Java applications using containers in the Cloud environment.

In this tutorial, I will give you an overview of how to up and run a Java application using Quarkus, to see, how long does it take to run an application with Quarkus!

Create new Quarkus project

Similar to Spring framework with Spring Initializr https://start.spring.io/, Quarkus also has a tool to help us quickly create a new Quarkus project at https://code.quarkus.io/.

You can quickly create a new Jakarta EE application running with Quarkus using this site.

For example, I create a new Jakarta EE MVC application by using RESTEasy JAX-RS, an implementation of Jakarta EE Java API for RESTful Web Services, as follows:

Press Generate your application:

and download the project to your computer.

Results of opening the project in IntelliJ:

By default, as you can see, if you choose to use RESTEasy JAX-RS in your project, Quarkus Code will generate a GreetingResource class that defines the endpoint “/hello” using JAX-RS:

Run application

You can run this application to use in development mode using the quarkus-maven-plugin that is declared with the generated project, by running the Maven command as follows:

Open the browser and go to the address http://localhost:8080/, you will see the following results:

Open IntellJ’s Console, you will see the following log lines:

In line 10 of the above log, if you notice, the start time of this example application is 2,791s. This is normal, nothing too surprising, right?

But if you now run this application by command line, with JAR file, by: open Terminal on macOS or Linux or Console on Windows, go to project folder, run command:

then go to the tartget/quarkus-app directory, run the command:

You will see the following result:

As you can see, the application start time is now less than half when we run in development mode in IntelliJ, only 0.779s.

If you build this application with the native profile using GraalVM with the native-image component, with the command:

then you can run the application directly using the file quarkus-jakartaee-mvc-1.0.0-SNAPSHOT-runner in the target directory of the project.

The application start time will surprise you as follows:

Very fast, right? Just press execute command and the application starts immediately. As you can see, it only takes 0.014s for our example application to be up and running. This is also the time that the application can be up and running on a Cloud environment.

2 thoughts on “Introduction about Quarkus

  1. Nice introduction! Maybe a followup article talking about Quarkus developer productivity like dev services, dev ui, continuous testing?

    BTW, Quarkus does not support Jakarta EE, although it does support many Jakarta specifications. Jakarta EE is a specification that specifies a collection of ~30+ Jakarta specifications and how they work together. Quarkus does fully support MicroProfile, however.

Add Comment