OpenJDK21
Install from Adoptium
1 cd ~
2 wget https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.7%2B6/OpenJDK21U-jdk_x64_linux_hotspot_21.0.7_6.tar.gz
3 tar tvzf OpenJDK21U-jdk_x64_linux_hotspot_21.0.7_6.tar.gz
4 tar xvzf OpenJDK21U-jdk_x64_linux_hotspot_21.0.7_6.tar.gz
5 nano ~/.bashrc
6 JAVA_HOME=/home/vitor/jdk-21.0.7+6/
7 MAVEN_HOME=/home/vitor/apache-maven-3.8.6/
8 PATH=$JAVA_HOME/bin/:$PATH:$MAVEN_HOME/bin/
9 # reload bashrc
10 # . ~/bashrc
11
Records
Introduced in release 16.
To model data as data. Easy and concise manner to declare data-carrier classes that by default make their data immutable. Can be described as nominal tuples.
1 record Point(int x, int y) { }
Virtual threads
Virtual threads are lightweight threads that dramatically reduce the effort of writing, maintaining, and observing high-throughput concurrent applications.
1 try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
2 IntStream.range(0, 10_000).forEach(i -> {
3 executor.submit(() -> {
4 Thread.sleep(Duration.ofSeconds(1));
5 return i;
6 });
7 });
8 } // executor.close() is called implicitly, and waits
9 //---
10
11 void handle(Request request, Response response) {
12 var url1 = ...
13 var url2 = ...
14
15 try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
16 var future1 = executor.submit(() -> fetchURL(url1));
17 var future2 = executor.submit(() -> fetchURL(url2));
18 response.send(future1.get() + future2.get());
19 } catch (ExecutionException | InterruptedException e) {
20 response.fail(e);
21 }
22 }
23
24 String fetchURL(URL url) throws IOException {
25 try (var in = url.openStream()) {
26 return new String(in.readAllBytes(), StandardCharsets.UTF_8);
27 }
28 }