SlideShare a Scribd company logo
1 of 66
Download to read offline
Joseph Kuo (CyberJos)
VP of Software Development &
Chief Architect
@ NextDrive 聯齊科技
New Features in Java 18 & 19
About Me
- 1993年Basic、1996年C/C++、1999年Java
1.2,以及 JavaScript、Python、……
- 主修應用數學。任職經歷:資訊教育機構、加
值簡訊服務、雲端影音平台、全球電子商務、
資安防護、用戶行為管理、物聯網
- 講師經歷:JCConf、Oracle Groundbreakers
Taiwan、AWS Summit
- 專長:軟體工程、設計模式、系統架構、雲端
與邊緣運算、物聯網
- 希望能一輩子玩技術寫程式到老
Taiwan Java User Group
- TWJUG 粉絲團:
https://www.facebook.com/groups/twjug
- 官方網站:
http://www.twjug.org/
- LINE 社群「Java 交流討論區」
Agenda
- Survey Report
- State of Java Ecosystem
- Features
- Preview & Incubator
Survey Report
TIOBE Index for Sep. 2022
Source: https://www.tiobe.com/tiobe-index/
TIOBE Index Trend
Source: https://www.tiobe.com/tiobe-index/
TIOBE Index History
Source: https://www.tiobe.com/tiobe-index/
GitHub Octoverse 2021
Source: https://octoverse.github.com/
Stackoverflow Survey 2021
Source: https://insights.stackoverflow.com/survey/2021
Stackoverflow Survey 2022
Source: https://survey.stackoverflow.co/2022/
Stackoverflow Survey 2022
Source: https://survey.stackoverflow.co/2022/
Most Demanded PL in 2022
- Published by DevJobsScanner on June 29,
2022
- From Oct-2021 to Jun-2022
- They have analyzed more than 7M
developer jobs, and only picked the job
offers that explicitly required a
programming language. Job offers with 4+
language or stack requirements were
discarded.
https://www.devjobsscanner.com/blog/top-8-most-demanded-languages-in-2022/
State of Java Ecosystem
2022 State of Java Ecosystem
- New Relic first published in March 2020
- 2022 state was published in April 2022
- Based on data gathered from millions of
applications providing performance data
Source: https://newrelic.com/resources/report/2022-state-of-java-ecosystem
Most Popular LTS
Most Popular non-LTS
Most Popular Vendor
Most Popular GC
Features
Simple Web Server
Simple Web Server
- JEP 408 (JDK 18)
- A command-line tool to start a minimal web
server that serves static files only
- Useful for prototyping and testing so no
CGI / servlet-like functionality is available
- Provide a default implementation via the
command line together with a small API for
programmatic creation and customization
Command Line Tool
Features & Limitation
- Only idempotent HEAD & GET
- Others receive a 501 Not implemented or a
405 Not Allowed response
- All files (except for links & hidden files) are
listed if no index file in the directory
- Only support HTTP 1.1, no HTTPS support
API Code
HTTP Client in Java 11
UTF-8 by Default
UTF-8 by Default
- JEP 400 (JDK 18)
- In JDK 17 and earlier, the default charset is
determined when the Java runtime starts
- More predictable and portable when their
code relies on the default charset
- Clarify where the standard Java API uses the
default charset
- Standardize on UTF-8 throughout the
standard Java APIs, except for console I/O
UTF-8 by Default
A Japanese text file encoded in UTF-8 on
macOS:
java.io.FileReader("hello.txt")
- macOS -> “こんにちは”
- Windows (en-US) -> “ã?“ã‚“ã?«ã?¡ã? ”
- Windows (ja-JP) -> “縺ォ縺。縺ッ”
Default Charset APIs
- InputStreamReader, OutputStreamWriter,
FileReader, FileWriter, & PrintStream:
constructors to create readers, writers, &
print streams to encode or decode
- Formatter & Scanner: constructors whose
results use the default charset.
- URLEncoder & URLDecoder: deprecated
methods that use the default charset
UTF-8 by Default
- Charset.defaultCharset() is "UTF-8"
unless configured
- file.encoding=COMPAT: default charset will
be like JDK 17 and earlier (OS, locale)
- Recommand to use
java –Dfile.encoding=UTF-8
for JDK 8 ~ 17
Code Snippets in JavaDoc
Code Snippets in JavaDoc
- JEP 413 (JDK 18)
- Introduce an @snippet tag for JavaDoc
- Facilitate the validation of source code
fragments by providing API access
- Enable modern styling & automatic linkage
of names to declarations
- Enable better IDE support for creating and
editing snippets
Current Approach
* <pre>{@code
* int sum = widgets.stream()
* .filter(w -> w.getColor() == RED)
* .mapToInt(w -> w.getWeight())
* .sum();
* }</pre>
->
Shortcomings
- No way to reliably detect and validate code
fragments so errors can occur
- No syntax highlighting
- Cannot contain '*/', HTML markup, and link
tags to link other APIs
Inline @snippet Tag
/**
* {@snippet :
* if (v.isPresent()) {
* System.out.println("v:" + v.get());
* }
* }
*/
External @snippet Tag
In A.java:
/**
* {@snippet file="B.java" region="xyz"}
*/
In B.java:
// @start region="xyz"
if (v.isPresent()) {
System.out.println(v.get());
}
// @end
Highlighting & Linking
/**
* {@snippet :
* System.out.println(x); // @highlight substring="println"
* for (var arg : x) { // @highlight region regex="bargb"
* if (!arg.isBlank()) {
* System.out.println(arg);
* } // @end
* }
* // @link region substring="System.out" target="System#out"
* System.out.println(x);
* // @end
* }
*/
Preview & Incubator
Pattern Matching for switch
Pattern Matching for switch
- JEP 420 (JDK 18), JEP 427 (JDK 19)
- Expand the expressiveness and applicability
of switch by allowing patterns in case labels
- Allow null case of switch when desired
- Increase the safety of switch statements by
requiring to cover all possible input values
Pattern Matching for instanceof
if (o instanceof String s) {
System.out.println("Str: " + s);
} else if (o instanceof Integer i && i < 100) {
System.out.println(”Small Int: " + i);
} else if (o instanceof Integer i) {
System.out.println("Int: " + i);
} else if (o instanceof Long l) {
System.out.println("Long: " + l);
} else {
System.out.println("Obj: " + o);
}
Pattern Matching for switch
switch (o) {
case null -> System.out.println(”NULL");
case String s -> System.out.println("Str: " + s);
case Integer i when i < 100
-> System.out.println(”Small Int: " + i);
case Integer i -> System.out.println("Int: " + i);
case Long l -> System.out.println("Long: " + l);
default -> System.out.println("Obj: " + o);
}
Selector Expression Types
record Point(int x, int y) {}
enum Color { RED, GREEN, BLUE }
switch (o) {
case null, String s -> System.out.println("Str: " + s);
case Color c -> System.out.println(”Color: " + c);
case Point p -> System.out.println(”Point: " + p);
case int[] ia -> System.out.println(”Array: " + ia);
default -> System.out.println("Obj: " + o);
}
Record Patterns
Record Patterns
- JEP 405 (JDK 19)
- Extend pattern matching to express more
sophisticated, composable data queries
- Do not change the syntax or semantics of
type patterns
Record Patterns
record Point(int x, int y) {}
if (o instanceof Point p) {
int x = p.x(); int y = p.y();
System.out.println(x + y);
}
->
if (o instanceof Point(int x, int y)) {
System.out.println(x + y);
}
Nested Patterns
record Point(int x, int y) {}
enum Color { RED, GREEN, BLUE }
record ColoredPoint(Point p, Color c) {}
record Rectangle(ColoredPoint uLeft, ColoredPoint dRight) {}
if (o instanceof Rectangle(ColoredPoint(Point p, Color c),
ColoredPoint dRight)) {
System.out.println(c); // print upperLeft color
}
Vector API
Vector API
- JEP 417 (JDK 18), JEP 426 (JDK 19)
- Express vector computations
- Clear and concise API running with reliable
runtime compilation and performance to
optimal vector instructions
Vector API
VectorSpecies<Float> S = FloatVector.SPECIES_PREFERRED;
void vectorComputation(float[] a, float[] b, float[] c) {
int upperBound = S.loopBound(a.length);
for (var i = 0; i < upperBound; i += S.length()) {
var m = S.indexInRange(i, a.length);
var va = FloatVector.fromArray(S, a, i);
var vb = FloatVector.fromArray(S, b, i);
var vc = va.mul(va).add(vb.mul(vb).neg();
vc.intoArray(c, i);
} // -> c[i] = (a[i]*a[i] + b[i]*b[i]) * -1.0f
}
Virtual Threads
Virtual Threads
- JEP 425 (JDK 19)
- Lightweight threads to dramatically reduce
the effort of writing, maintaining, and
observing high-throughput concurrent
applications
- Enable server applications written in the
simple thread-per-request style to scale w/
near-optimal hardware utilization
- Easy to use, debug and profile with existing
API and JDK tools
Thread-per-request Style
- Server application handles a request by
dedicating a thread for its entire duration
- Little's Law: For a given duration (latency),
number of requests that a server handles at
the same time (concurrency) must grow in
proportion to the rate of arrival (throughput)
- But thread number is limited because JDK
uses OS threads which are costly
Improve Scalability w/ Async
- Async style uses a separate set of I/O
methods not to wait for I/O operations
- Developers must break down logic into
small stages like lambda expressions, and
compose them into a sequential pipeline
- Each stage of a request may execute on a
different thread, and stack traces provide
no usable context
Preserving thread-per-request
- A Java thread was like an OS thread
- 為了使應用擴展,同時與平台保持協作,因此
有效率地改善實作,通過將大量虛擬執行緒映
射到作業系統執行緒,達成執行緒數量增長
- 一個虛擬執行緒會被臨時對映到載體執行緒池
中。一旦虛擬執行緒遇到阻塞操作,該虛擬執
行緒就會從載體執行緒中移除,而載體執行緒
可以執行另一個虛擬執行緒(新的或之前被阻
塞的)
Virtual Threads
try (var executor =
Executors.newVirtualThreadPerTaskExecutor()) {
IntStream.range(0, 10_000).forEach(i -> {
executor.submit(() -> {
Thread.sleep(Duration.ofSeconds(1));
return i;
});
});
}
Higher Throughput
- Virtual Threads 並不是執行速度更快,事實上
它與平台執行緒在執行代碼時的速度一致。它
是為了提供更高的吞吐量,而不是更低的延遲
而存在的
- 適用於並發執行緒數量高且非 CPU 負載高時
- 它不需要連線池,因為它是便宜且大量的,時
間只有單次HTTP請求或DB查詢。相對來說,
平台執行緒是昂貴且深度使用stack,所以需要
連線池,保持其長壽且能調度
Initial Virtual Threads
Executors.newVirtualThreadPerTaskExecutor()
Thread.startVirtualThread(() -> {
// code to run in thread
});
Thread.ofVirtual().start(() -> {
// code to run in thread
});
How to Compile
- javac --release 19 --enable-preview 
Main.java
- java --enable-preview Main.java
- jshell --enable-preview
Others
Others
- JEP 416: Reimplement Core Reflection w/
Method Handles
- JEP 418: Internet-Address Resolution SPI
- JEP 421: Deprecate Finalization for Removal
(protected void finalize())
- JEP 422: Linux/RISC-V Port
- JEP 419, 424: Foreign Function & Memory
(FFM) API
Thank You

More Related Content

What's hot

ES6 presentation
ES6 presentationES6 presentation
ES6 presentationritika1
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js ExpressEyal Vardi
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with ExamplesGabriele Lana
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentationToufiq Mahmud
 
Introduction to Kafka Streams
Introduction to Kafka StreamsIntroduction to Kafka Streams
Introduction to Kafka StreamsGuozhang Wang
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKJosé Paumard
 
SQL for NoSQL and how Apache Calcite can help
SQL for NoSQL and how  Apache Calcite can helpSQL for NoSQL and how  Apache Calcite can help
SQL for NoSQL and how Apache Calcite can helpChristian Tzolov
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6Rob Eisenberg
 
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafSpring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafThymeleaf
 
Introduction to Kafka Cruise Control
Introduction to Kafka Cruise ControlIntroduction to Kafka Cruise Control
Introduction to Kafka Cruise ControlJiangjie Qin
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and DeploymentBG Java EE Course
 
Learn Oracle WebLogic Server 12c Administration
Learn Oracle WebLogic Server 12c AdministrationLearn Oracle WebLogic Server 12c Administration
Learn Oracle WebLogic Server 12c AdministrationRevelation Technologies
 
The never-ending REST API design debate
The never-ending REST API design debateThe never-ending REST API design debate
The never-ending REST API design debateRestlet
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous JavascriptGarrett Welson
 
Building Web Apps with WebAssembly and Blazor
Building Web Apps with WebAssembly and BlazorBuilding Web Apps with WebAssembly and Blazor
Building Web Apps with WebAssembly and BlazorAmir Zuker
 
Java11 New Features
Java11 New FeaturesJava11 New Features
Java11 New FeaturesHaim Michael
 

What's hot (20)

ES6 presentation
ES6 presentationES6 presentation
ES6 presentation
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentation
 
Introduction to Kafka Streams
Introduction to Kafka StreamsIntroduction to Kafka Streams
Introduction to Kafka Streams
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
 
SQL for NoSQL and how Apache Calcite can help
SQL for NoSQL and how  Apache Calcite can helpSQL for NoSQL and how  Apache Calcite can help
SQL for NoSQL and how Apache Calcite can help
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafSpring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
 
Introduction to Kafka Cruise Control
Introduction to Kafka Cruise ControlIntroduction to Kafka Cruise Control
Introduction to Kafka Cruise Control
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
 
Learn Oracle WebLogic Server 12c Administration
Learn Oracle WebLogic Server 12c AdministrationLearn Oracle WebLogic Server 12c Administration
Learn Oracle WebLogic Server 12c Administration
 
The never-ending REST API design debate
The never-ending REST API design debateThe never-ending REST API design debate
The never-ending REST API design debate
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
 
Apache tomcat
Apache tomcatApache tomcat
Apache tomcat
 
Building Web Apps with WebAssembly and Blazor
Building Web Apps with WebAssembly and BlazorBuilding Web Apps with WebAssembly and Blazor
Building Web Apps with WebAssembly and Blazor
 
Java11 New Features
Java11 New FeaturesJava11 New Features
Java11 New Features
 

Similar to JCConf 2022 - New Features in Java 18 & 19

Web Template Mechanisms in SOC Verification - DVCon.pdf
Web Template Mechanisms in SOC Verification - DVCon.pdfWeb Template Mechanisms in SOC Verification - DVCon.pdf
Web Template Mechanisms in SOC Verification - DVCon.pdfSamHoney6
 
Writing Continuous Applications with Structured Streaming PySpark API
Writing Continuous Applications with Structured Streaming PySpark APIWriting Continuous Applications with Structured Streaming PySpark API
Writing Continuous Applications with Structured Streaming PySpark APIDatabricks
 
Writing Continuous Applications with Structured Streaming Python APIs in Apac...
Writing Continuous Applications with Structured Streaming Python APIs in Apac...Writing Continuous Applications with Structured Streaming Python APIs in Apac...
Writing Continuous Applications with Structured Streaming Python APIs in Apac...Databricks
 
Rapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesRapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesciklum_ods
 
Big Data Processing with .NET and Spark (SQLBits 2020)
Big Data Processing with .NET and Spark (SQLBits 2020)Big Data Processing with .NET and Spark (SQLBits 2020)
Big Data Processing with .NET and Spark (SQLBits 2020)Michael Rys
 
How to use Parquet as a Sasis for ETL and Analytics
How to use Parquet as a Sasis for ETL and AnalyticsHow to use Parquet as a Sasis for ETL and Analytics
How to use Parquet as a Sasis for ETL and AnalyticsDataWorks Summit
 
Introduction to DataFusion An Embeddable Query Engine Written in Rust
Introduction to DataFusion  An Embeddable Query Engine Written in RustIntroduction to DataFusion  An Embeddable Query Engine Written in Rust
Introduction to DataFusion An Embeddable Query Engine Written in RustAndrew Lamb
 
Jump Start into Apache® Spark™ and Databricks
Jump Start into Apache® Spark™ and DatabricksJump Start into Apache® Spark™ and Databricks
Jump Start into Apache® Spark™ and DatabricksDatabricks
 
Introduction to Structured Streaming
Introduction to Structured StreamingIntroduction to Structured Streaming
Introduction to Structured StreamingKnoldus Inc.
 
Spark Summit EU 2016 Keynote - Simplifying Big Data in Apache Spark 2.0
Spark Summit EU 2016 Keynote - Simplifying Big Data in Apache Spark 2.0Spark Summit EU 2016 Keynote - Simplifying Big Data in Apache Spark 2.0
Spark Summit EU 2016 Keynote - Simplifying Big Data in Apache Spark 2.0Databricks
 
FP - Découverte de Play Framework Scala
FP - Découverte de Play Framework ScalaFP - Découverte de Play Framework Scala
FP - Découverte de Play Framework ScalaKévin Margueritte
 
A Deep Dive into Structured Streaming: Apache Spark Meetup at Bloomberg 2016
A Deep Dive into Structured Streaming:  Apache Spark Meetup at Bloomberg 2016 A Deep Dive into Structured Streaming:  Apache Spark Meetup at Bloomberg 2016
A Deep Dive into Structured Streaming: Apache Spark Meetup at Bloomberg 2016 Databricks
 
The Art of Metaprogramming in Java
The Art of Metaprogramming in Java  The Art of Metaprogramming in Java
The Art of Metaprogramming in Java Abdelmonaim Remani
 
JRuby with Java Code in Data Processing World
JRuby with Java Code in Data Processing WorldJRuby with Java Code in Data Processing World
JRuby with Java Code in Data Processing WorldSATOSHI TAGOMORI
 
Running High-Speed Serverless with nuclio
Running High-Speed Serverless with nuclioRunning High-Speed Serverless with nuclio
Running High-Speed Serverless with nuclioiguazio
 
Quantifying Container Runtime Performance: OSCON 2017 Open Container Day
Quantifying Container Runtime Performance: OSCON 2017 Open Container DayQuantifying Container Runtime Performance: OSCON 2017 Open Container Day
Quantifying Container Runtime Performance: OSCON 2017 Open Container DayPhil Estes
 

Similar to JCConf 2022 - New Features in Java 18 & 19 (20)

Web Template Mechanisms in SOC Verification - DVCon.pdf
Web Template Mechanisms in SOC Verification - DVCon.pdfWeb Template Mechanisms in SOC Verification - DVCon.pdf
Web Template Mechanisms in SOC Verification - DVCon.pdf
 
Writing Continuous Applications with Structured Streaming PySpark API
Writing Continuous Applications with Structured Streaming PySpark APIWriting Continuous Applications with Structured Streaming PySpark API
Writing Continuous Applications with Structured Streaming PySpark API
 
Writing Continuous Applications with Structured Streaming Python APIs in Apac...
Writing Continuous Applications with Structured Streaming Python APIs in Apac...Writing Continuous Applications with Structured Streaming Python APIs in Apac...
Writing Continuous Applications with Structured Streaming Python APIs in Apac...
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
Introduction to Apache Beam
Introduction to Apache BeamIntroduction to Apache Beam
Introduction to Apache Beam
 
Rapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesRapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devices
 
Big Data Processing with .NET and Spark (SQLBits 2020)
Big Data Processing with .NET and Spark (SQLBits 2020)Big Data Processing with .NET and Spark (SQLBits 2020)
Big Data Processing with .NET and Spark (SQLBits 2020)
 
SAP hands on lab_en
SAP hands on lab_enSAP hands on lab_en
SAP hands on lab_en
 
How to use Parquet as a Sasis for ETL and Analytics
How to use Parquet as a Sasis for ETL and AnalyticsHow to use Parquet as a Sasis for ETL and Analytics
How to use Parquet as a Sasis for ETL and Analytics
 
Introduction to DataFusion An Embeddable Query Engine Written in Rust
Introduction to DataFusion  An Embeddable Query Engine Written in RustIntroduction to DataFusion  An Embeddable Query Engine Written in Rust
Introduction to DataFusion An Embeddable Query Engine Written in Rust
 
Jump Start into Apache® Spark™ and Databricks
Jump Start into Apache® Spark™ and DatabricksJump Start into Apache® Spark™ and Databricks
Jump Start into Apache® Spark™ and Databricks
 
Introduction to Structured Streaming
Introduction to Structured StreamingIntroduction to Structured Streaming
Introduction to Structured Streaming
 
Spark Summit EU 2016 Keynote - Simplifying Big Data in Apache Spark 2.0
Spark Summit EU 2016 Keynote - Simplifying Big Data in Apache Spark 2.0Spark Summit EU 2016 Keynote - Simplifying Big Data in Apache Spark 2.0
Spark Summit EU 2016 Keynote - Simplifying Big Data in Apache Spark 2.0
 
FP - Découverte de Play Framework Scala
FP - Découverte de Play Framework ScalaFP - Découverte de Play Framework Scala
FP - Découverte de Play Framework Scala
 
A Deep Dive into Structured Streaming: Apache Spark Meetup at Bloomberg 2016
A Deep Dive into Structured Streaming:  Apache Spark Meetup at Bloomberg 2016 A Deep Dive into Structured Streaming:  Apache Spark Meetup at Bloomberg 2016
A Deep Dive into Structured Streaming: Apache Spark Meetup at Bloomberg 2016
 
The Art of Metaprogramming in Java
The Art of Metaprogramming in Java  The Art of Metaprogramming in Java
The Art of Metaprogramming in Java
 
JRuby with Java Code in Data Processing World
JRuby with Java Code in Data Processing WorldJRuby with Java Code in Data Processing World
JRuby with Java Code in Data Processing World
 
Running High-Speed Serverless with nuclio
Running High-Speed Serverless with nuclioRunning High-Speed Serverless with nuclio
Running High-Speed Serverless with nuclio
 
Quantifying Container Runtime Performance: OSCON 2017 Open Container Day
Quantifying Container Runtime Performance: OSCON 2017 Open Container DayQuantifying Container Runtime Performance: OSCON 2017 Open Container Day
Quantifying Container Runtime Performance: OSCON 2017 Open Container Day
 
Anton_Vysotskiy_resume
Anton_Vysotskiy_resumeAnton_Vysotskiy_resume
Anton_Vysotskiy_resume
 

More from Joseph Kuo

JCConf 2023 - 深入淺出 Java 21 功能
JCConf 2023 - 深入淺出 Java 21 功能JCConf 2023 - 深入淺出 Java 21 功能
JCConf 2023 - 深入淺出 Java 21 功能Joseph Kuo
 
JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020Joseph Kuo
 
TWJUG x Oracle Groundbreakers 2019 Taiwan - What’s New in Last Java Versions
TWJUG x Oracle Groundbreakers 2019 Taiwan - What’s New in Last Java VersionsTWJUG x Oracle Groundbreakers 2019 Taiwan - What’s New in Last Java Versions
TWJUG x Oracle Groundbreakers 2019 Taiwan - What’s New in Last Java VersionsJoseph Kuo
 
JCConf 2018 - Retrospect and Prospect of Java
JCConf 2018 - Retrospect and Prospect of JavaJCConf 2018 - Retrospect and Prospect of Java
JCConf 2018 - Retrospect and Prospect of JavaJoseph Kuo
 
JCConf 2017 - Next Generation of Cloud Computing: Edge Computing and Apache E...
JCConf 2017 - Next Generation of Cloud Computing: Edge Computing and Apache E...JCConf 2017 - Next Generation of Cloud Computing: Edge Computing and Apache E...
JCConf 2017 - Next Generation of Cloud Computing: Edge Computing and Apache E...Joseph Kuo
 
JCConf 2016 - Cloud Computing Applications - Hazelcast, Spark and Ignite
JCConf 2016 - Cloud Computing Applications - Hazelcast, Spark and IgniteJCConf 2016 - Cloud Computing Applications - Hazelcast, Spark and Ignite
JCConf 2016 - Cloud Computing Applications - Hazelcast, Spark and IgniteJoseph Kuo
 
Establish The Core of Cloud Computing Application by Using Hazelcast (Chinese)
Establish The Core of  Cloud Computing Application  by Using Hazelcast (Chinese)Establish The Core of  Cloud Computing Application  by Using Hazelcast (Chinese)
Establish The Core of Cloud Computing Application by Using Hazelcast (Chinese)Joseph Kuo
 

More from Joseph Kuo (7)

JCConf 2023 - 深入淺出 Java 21 功能
JCConf 2023 - 深入淺出 Java 21 功能JCConf 2023 - 深入淺出 Java 21 功能
JCConf 2023 - 深入淺出 Java 21 功能
 
JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020
 
TWJUG x Oracle Groundbreakers 2019 Taiwan - What’s New in Last Java Versions
TWJUG x Oracle Groundbreakers 2019 Taiwan - What’s New in Last Java VersionsTWJUG x Oracle Groundbreakers 2019 Taiwan - What’s New in Last Java Versions
TWJUG x Oracle Groundbreakers 2019 Taiwan - What’s New in Last Java Versions
 
JCConf 2018 - Retrospect and Prospect of Java
JCConf 2018 - Retrospect and Prospect of JavaJCConf 2018 - Retrospect and Prospect of Java
JCConf 2018 - Retrospect and Prospect of Java
 
JCConf 2017 - Next Generation of Cloud Computing: Edge Computing and Apache E...
JCConf 2017 - Next Generation of Cloud Computing: Edge Computing and Apache E...JCConf 2017 - Next Generation of Cloud Computing: Edge Computing and Apache E...
JCConf 2017 - Next Generation of Cloud Computing: Edge Computing and Apache E...
 
JCConf 2016 - Cloud Computing Applications - Hazelcast, Spark and Ignite
JCConf 2016 - Cloud Computing Applications - Hazelcast, Spark and IgniteJCConf 2016 - Cloud Computing Applications - Hazelcast, Spark and Ignite
JCConf 2016 - Cloud Computing Applications - Hazelcast, Spark and Ignite
 
Establish The Core of Cloud Computing Application by Using Hazelcast (Chinese)
Establish The Core of  Cloud Computing Application  by Using Hazelcast (Chinese)Establish The Core of  Cloud Computing Application  by Using Hazelcast (Chinese)
Establish The Core of Cloud Computing Application by Using Hazelcast (Chinese)
 

Recently uploaded

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 

Recently uploaded (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 

JCConf 2022 - New Features in Java 18 & 19

  • 1. Joseph Kuo (CyberJos) VP of Software Development & Chief Architect @ NextDrive 聯齊科技 New Features in Java 18 & 19
  • 2. About Me - 1993年Basic、1996年C/C++、1999年Java 1.2,以及 JavaScript、Python、…… - 主修應用數學。任職經歷:資訊教育機構、加 值簡訊服務、雲端影音平台、全球電子商務、 資安防護、用戶行為管理、物聯網 - 講師經歷:JCConf、Oracle Groundbreakers Taiwan、AWS Summit - 專長:軟體工程、設計模式、系統架構、雲端 與邊緣運算、物聯網 - 希望能一輩子玩技術寫程式到老
  • 3. Taiwan Java User Group - TWJUG 粉絲團: https://www.facebook.com/groups/twjug - 官方網站: http://www.twjug.org/ - LINE 社群「Java 交流討論區」
  • 4. Agenda - Survey Report - State of Java Ecosystem - Features - Preview & Incubator
  • 6. TIOBE Index for Sep. 2022 Source: https://www.tiobe.com/tiobe-index/
  • 7. TIOBE Index Trend Source: https://www.tiobe.com/tiobe-index/
  • 8. TIOBE Index History Source: https://www.tiobe.com/tiobe-index/
  • 9. GitHub Octoverse 2021 Source: https://octoverse.github.com/
  • 10. Stackoverflow Survey 2021 Source: https://insights.stackoverflow.com/survey/2021
  • 11. Stackoverflow Survey 2022 Source: https://survey.stackoverflow.co/2022/
  • 12. Stackoverflow Survey 2022 Source: https://survey.stackoverflow.co/2022/
  • 13. Most Demanded PL in 2022 - Published by DevJobsScanner on June 29, 2022 - From Oct-2021 to Jun-2022 - They have analyzed more than 7M developer jobs, and only picked the job offers that explicitly required a programming language. Job offers with 4+ language or stack requirements were discarded. https://www.devjobsscanner.com/blog/top-8-most-demanded-languages-in-2022/
  • 14.
  • 15.
  • 16.
  • 17. State of Java Ecosystem
  • 18. 2022 State of Java Ecosystem - New Relic first published in March 2020 - 2022 state was published in April 2022 - Based on data gathered from millions of applications providing performance data Source: https://newrelic.com/resources/report/2022-state-of-java-ecosystem
  • 25. Simple Web Server - JEP 408 (JDK 18) - A command-line tool to start a minimal web server that serves static files only - Useful for prototyping and testing so no CGI / servlet-like functionality is available - Provide a default implementation via the command line together with a small API for programmatic creation and customization
  • 27. Features & Limitation - Only idempotent HEAD & GET - Others receive a 501 Not implemented or a 405 Not Allowed response - All files (except for links & hidden files) are listed if no index file in the directory - Only support HTTP 1.1, no HTTPS support
  • 29. HTTP Client in Java 11
  • 31. UTF-8 by Default - JEP 400 (JDK 18) - In JDK 17 and earlier, the default charset is determined when the Java runtime starts - More predictable and portable when their code relies on the default charset - Clarify where the standard Java API uses the default charset - Standardize on UTF-8 throughout the standard Java APIs, except for console I/O
  • 32. UTF-8 by Default A Japanese text file encoded in UTF-8 on macOS: java.io.FileReader("hello.txt") - macOS -> “こんにちは” - Windows (en-US) -> “ã?“ã‚“ã?«ã?¡ã? ” - Windows (ja-JP) -> “縺ォ縺。縺ッ”
  • 33. Default Charset APIs - InputStreamReader, OutputStreamWriter, FileReader, FileWriter, & PrintStream: constructors to create readers, writers, & print streams to encode or decode - Formatter & Scanner: constructors whose results use the default charset. - URLEncoder & URLDecoder: deprecated methods that use the default charset
  • 34. UTF-8 by Default - Charset.defaultCharset() is "UTF-8" unless configured - file.encoding=COMPAT: default charset will be like JDK 17 and earlier (OS, locale) - Recommand to use java –Dfile.encoding=UTF-8 for JDK 8 ~ 17
  • 35. Code Snippets in JavaDoc
  • 36. Code Snippets in JavaDoc - JEP 413 (JDK 18) - Introduce an @snippet tag for JavaDoc - Facilitate the validation of source code fragments by providing API access - Enable modern styling & automatic linkage of names to declarations - Enable better IDE support for creating and editing snippets
  • 37. Current Approach * <pre>{@code * int sum = widgets.stream() * .filter(w -> w.getColor() == RED) * .mapToInt(w -> w.getWeight()) * .sum(); * }</pre> ->
  • 38. Shortcomings - No way to reliably detect and validate code fragments so errors can occur - No syntax highlighting - Cannot contain '*/', HTML markup, and link tags to link other APIs
  • 39. Inline @snippet Tag /** * {@snippet : * if (v.isPresent()) { * System.out.println("v:" + v.get()); * } * } */
  • 40. External @snippet Tag In A.java: /** * {@snippet file="B.java" region="xyz"} */ In B.java: // @start region="xyz" if (v.isPresent()) { System.out.println(v.get()); } // @end
  • 41. Highlighting & Linking /** * {@snippet : * System.out.println(x); // @highlight substring="println" * for (var arg : x) { // @highlight region regex="bargb" * if (!arg.isBlank()) { * System.out.println(arg); * } // @end * } * // @link region substring="System.out" target="System#out" * System.out.println(x); * // @end * } */
  • 44. Pattern Matching for switch - JEP 420 (JDK 18), JEP 427 (JDK 19) - Expand the expressiveness and applicability of switch by allowing patterns in case labels - Allow null case of switch when desired - Increase the safety of switch statements by requiring to cover all possible input values
  • 45. Pattern Matching for instanceof if (o instanceof String s) { System.out.println("Str: " + s); } else if (o instanceof Integer i && i < 100) { System.out.println(”Small Int: " + i); } else if (o instanceof Integer i) { System.out.println("Int: " + i); } else if (o instanceof Long l) { System.out.println("Long: " + l); } else { System.out.println("Obj: " + o); }
  • 46. Pattern Matching for switch switch (o) { case null -> System.out.println(”NULL"); case String s -> System.out.println("Str: " + s); case Integer i when i < 100 -> System.out.println(”Small Int: " + i); case Integer i -> System.out.println("Int: " + i); case Long l -> System.out.println("Long: " + l); default -> System.out.println("Obj: " + o); }
  • 47. Selector Expression Types record Point(int x, int y) {} enum Color { RED, GREEN, BLUE } switch (o) { case null, String s -> System.out.println("Str: " + s); case Color c -> System.out.println(”Color: " + c); case Point p -> System.out.println(”Point: " + p); case int[] ia -> System.out.println(”Array: " + ia); default -> System.out.println("Obj: " + o); }
  • 49. Record Patterns - JEP 405 (JDK 19) - Extend pattern matching to express more sophisticated, composable data queries - Do not change the syntax or semantics of type patterns
  • 50. Record Patterns record Point(int x, int y) {} if (o instanceof Point p) { int x = p.x(); int y = p.y(); System.out.println(x + y); } -> if (o instanceof Point(int x, int y)) { System.out.println(x + y); }
  • 51. Nested Patterns record Point(int x, int y) {} enum Color { RED, GREEN, BLUE } record ColoredPoint(Point p, Color c) {} record Rectangle(ColoredPoint uLeft, ColoredPoint dRight) {} if (o instanceof Rectangle(ColoredPoint(Point p, Color c), ColoredPoint dRight)) { System.out.println(c); // print upperLeft color }
  • 53. Vector API - JEP 417 (JDK 18), JEP 426 (JDK 19) - Express vector computations - Clear and concise API running with reliable runtime compilation and performance to optimal vector instructions
  • 54. Vector API VectorSpecies<Float> S = FloatVector.SPECIES_PREFERRED; void vectorComputation(float[] a, float[] b, float[] c) { int upperBound = S.loopBound(a.length); for (var i = 0; i < upperBound; i += S.length()) { var m = S.indexInRange(i, a.length); var va = FloatVector.fromArray(S, a, i); var vb = FloatVector.fromArray(S, b, i); var vc = va.mul(va).add(vb.mul(vb).neg(); vc.intoArray(c, i); } // -> c[i] = (a[i]*a[i] + b[i]*b[i]) * -1.0f }
  • 56. Virtual Threads - JEP 425 (JDK 19) - Lightweight threads to dramatically reduce the effort of writing, maintaining, and observing high-throughput concurrent applications - Enable server applications written in the simple thread-per-request style to scale w/ near-optimal hardware utilization - Easy to use, debug and profile with existing API and JDK tools
  • 57. Thread-per-request Style - Server application handles a request by dedicating a thread for its entire duration - Little's Law: For a given duration (latency), number of requests that a server handles at the same time (concurrency) must grow in proportion to the rate of arrival (throughput) - But thread number is limited because JDK uses OS threads which are costly
  • 58. Improve Scalability w/ Async - Async style uses a separate set of I/O methods not to wait for I/O operations - Developers must break down logic into small stages like lambda expressions, and compose them into a sequential pipeline - Each stage of a request may execute on a different thread, and stack traces provide no usable context
  • 59. Preserving thread-per-request - A Java thread was like an OS thread - 為了使應用擴展,同時與平台保持協作,因此 有效率地改善實作,通過將大量虛擬執行緒映 射到作業系統執行緒,達成執行緒數量增長 - 一個虛擬執行緒會被臨時對映到載體執行緒池 中。一旦虛擬執行緒遇到阻塞操作,該虛擬執 行緒就會從載體執行緒中移除,而載體執行緒 可以執行另一個虛擬執行緒(新的或之前被阻 塞的)
  • 60. Virtual Threads try (var executor = Executors.newVirtualThreadPerTaskExecutor()) { IntStream.range(0, 10_000).forEach(i -> { executor.submit(() -> { Thread.sleep(Duration.ofSeconds(1)); return i; }); }); }
  • 61. Higher Throughput - Virtual Threads 並不是執行速度更快,事實上 它與平台執行緒在執行代碼時的速度一致。它 是為了提供更高的吞吐量,而不是更低的延遲 而存在的 - 適用於並發執行緒數量高且非 CPU 負載高時 - 它不需要連線池,因為它是便宜且大量的,時 間只有單次HTTP請求或DB查詢。相對來說, 平台執行緒是昂貴且深度使用stack,所以需要 連線池,保持其長壽且能調度
  • 62. Initial Virtual Threads Executors.newVirtualThreadPerTaskExecutor() Thread.startVirtualThread(() -> { // code to run in thread }); Thread.ofVirtual().start(() -> { // code to run in thread });
  • 63. How to Compile - javac --release 19 --enable-preview Main.java - java --enable-preview Main.java - jshell --enable-preview
  • 65. Others - JEP 416: Reimplement Core Reflection w/ Method Handles - JEP 418: Internet-Address Resolution SPI - JEP 421: Deprecate Finalization for Removal (protected void finalize()) - JEP 422: Linux/RISC-V Port - JEP 419, 424: Foreign Function & Memory (FFM) API