SlideShare a Scribd company logo
Revolutionize Java Database App
Development with Reactive Streams and
Virtual Threads
The Developer’s Conference – TDC Connections 2023
Juarez Barbosa Junior - @juarezjunior
March 2023
Copyright © 2022, Oracle and/or its affiliates
Agenda
• Java App Dev with Oracle Database
• Support for the Latest Java Versions
• Overview of Oracle DB Access with Java
• Oracle JDBC – Sync and Async
• Classic Java Platform Threads
• Project Loom – Virtual Threads
• Virtual Threads - JEP 425 (Preview API)
• Demo # 1: Virtual vs Platform Threads
• Reactive JDBC - Synchronous vs Asynchronous JDBC
• Reactive Streams Ingestion (RSI)
• Demo # 2: Reactive Streams Ingestion (RSI)
• From Sync to Reactive JDBC: Oracle R2DBC
• Demo # 3: Oracle R2DBC
• Live Labs/Free Oracle Cloud Account/Oracle ACE Program
Copyright © 2022, Oracle and/or its affiliates
Copyright © 2022, Oracle and/or its affiliates
Java App Dev with Oracle Database
Copyright © 2022, Oracle and/or its affiliates
Support for the Latest Java Versions
• Java 11 - native support, compiled with it
• Java 17 - certified
• JDBC Standards - 4.2 and 4.3
• JMS 1.1 - latest is 2.0
• GraalVM - native image instrumentation
• Reactive Streams - Java Flow API support
• Project Loom - Virtual Threads support
• Data access is critical in mission-critical apps
Copyright © 2022, Oracle and/or its affiliates
Overview of Oracle DB Access with Java
User
Java
Code
JDBC
Reactive
Extension Standard
JDBC API
R2DBC
+
3rd party
Reactive
Streams
Libraries
Async call with non-blocking
backpressure
operators (map, reduce, filters),
concurrency modeling,
monitoring, tracing
Implements Java SE
reactive stream
interface (Flow)
Full Reactive
Streams
Sync/blocking JDBC calls
Java
Business
Logic
User Java code
Oracle
Database
Oracle JDBC
driver
VTs/lightweight JDBC calls
Copyright © 2022, Oracle and/or its affiliates
Oracle JDBC – Sync and Async
⚫ Reactive Programming
− Asynchronous database access with non-blocking network I/O
− Oracle R2DBC + Oracle JDBC Reactive Extensions + Oracle Reactive Streams Ingestion
− Application call stack must be fully asynchronous
− Libraries are here to support it: Reactor, RxJava, Akka, Vert.x
⚫ Project Loom/Virtual Threads
− Synchronous database access with lightweight threads
− Standard JDBC + Virtual Threads
− Client application call stack may use conventional (synchronous) code
− Libraries must be compatible with Virtual Threads
− Oracle instrumented the Oracle JDBC 21c driver to support Virtual Threads
Copyright © 2022, Oracle and/or its affiliates
Classic Java Platform Threads
⚫ Blocking Threads
⚫ A JDBC call blocks a thread for 100’s of milliseconds (thread-per-request style)
⚫ Thread count increases linearly with the number of JDBC calls
⚫ Performance degrades as the number of threads increases
⚫ 1 MB of stack memory per thread
⚫ Scheduling many platform threads is expensive
⚫ Preemptive scheduling vs time-slicing
Copyright © 2022, Oracle and/or its affiliates
Virtual Threads - JEP 425 (Preview API)
⚫ Virtual Threads
⚫ Lightweight threads that dramatically reduce the effort of writing, maintaining, and
observing high-throughput concurrent applications
⚫ Enable applications written in the simple thread-per-request style to scale with near-
optimal hardware utilization
⚫ Enable existing code that uses the java.lang.Thread API to adopt virtual threads with
minimal change
⚫ Enable easy troubleshooting, debugging, and profiling of virtual threads with existing
JDK tools
⚫ Do not remove the traditional implementation of threads
⚫ Do not alter the basic concurrency model of Java
Copyright © 2022, Oracle and/or its affiliates
Demo # 1: Virtual vs Platform Threads
⚫ Virtual Threads versus Platform Threads
⚫ JEP 425 Virtual Threads (Project)
⚫ Runs on Java 19 (Preview API)
⚫ javac --release 19 --enable-preview
⚫ java --enable-preview
⚫ Comparison of OS resources consumption (Threads only + JDBC)
⚫ Oracle JDBC Driver 21c instrumented to support Virtual Threads
⚫ API is Oracle JDBC with the Java SE library (Executor, ThreadFactory)
Copyright © 2022, Oracle and/or its affiliates
Reactive JDBC - Synchronous vs Asynchronous JDBC
Setup
Blocking
Handle Result
Setup
Non-Blocking
Handle Result
Synchronous JDBC Setup
Blocking
Handle Result
Setup
Non-Blocking
Handle Result
Setup
Non-Blocking
Handle Result
Reactive JDBC
Database
Setup
Blocking
Handle Result
Database
Copyright © 2022, Oracle and/or its affiliates
Reactive Streams Ingestion (RSI)
⚫ Java Library for Reactive Streams Ingestion
⚫ Streaming capability: Ingest data in an unblocking, and
reactive way from a large group of clients
⚫ Group records through RAC (Real App Clusters),
and Shard affinity using native UCP (Universal Connection
Pool)
⚫ Optimize CPU allocation while decoupling record
Processing from I/O
⚫ Fastest insert method for the Oracle Database through
Direct Path Insert, bypassing SQL and writing directly into the DB files
Copyright © 2022, Oracle and/or its affiliates
Demo # 2: Reactive Streams Ingestion (RSI)
Container
Pipelines,
Jenkins, etc.
Build
Test
Push
Push Docker
images to
Registry
Cloud
Infrastructur
e Registry
Container
Engine for
Kubernetes
Pull images
from Registry
Deploy
images to
production
Kubernetes
worker nodes
Containers
running
microservices
deployed over
Kubernetes
ORACLE CLOUD INFRASTRUCTURE
ATP, ADW, ATP-D,
AFDW-D
Memoptimized
Rowstore
RSI Runtime: Non-
blocking, optimized library
for streaming data
through Direct Path, Shard
& RAC/FAN support.
HTTP / REST Engine over
Helidon
Define build
for CI/CD
toolchain
gRPC / AMQP / MQTT
Engines
Microservices
Files / Logs
IoT
Devices
/
Apps
cv
MQTT
gRPC
AMQP
HTTP / REST
JDBC
Direct Path
INSERT
Record
Streaming
over
multiple
protocols.
Copyright © 2022, Oracle and/or its affiliates
From Sync to Reactive JDBC: Oracle R2DBC
static String queryJdbc(java.sql.Connection connection) throws
SQLException {
try (java.sql.Statement statement = connection.createStatement()) {
ResultSet resultSet =
statement.executeQuery("SELECT * FROM CUSTOMERS");
if (resultSet.next())
return resultSet.getString(1);
else
throw new NoSuchElementException("Query returned zero rows");
}
}
static Publisher<String> queryR2dbc(io.r2dbc.spi.Connection
connection) {
return Flux.from(connection.createStatement(
"SELECT * FROM CUSTOMERS")
.execute())
.flatMap(result ->
result.map(row -> row.get(0, String.class)))
.switchIfEmpty(Flux.error(
new NoSuchElementException("Query returned zero rows")));
}
Copyright © 2022, Oracle and/or its affiliates
Demo # 3: Oracle R2DBC
⚫ Oracle Reactive Relational Database Connectivity (R2DBC)
⚫ Oracle R2DBC Driver is a Java library that supports reactive
Programming with Oracle Database
⚫ It implements the R2DBC Service Provider Interface (SPI) as
specified by the Reactive Relational Database Connectivity (R2DBC)
⚫ The R2DBC SPI exposes Reactive Streams as an abstraction for
Remote database operations
⚫ The sample code uses Project Reactor. It could use RxJava, Akka,
or any RS library
⚫ Runs on Java 11+
Virtual Threads or
Reactive?
• Oracle JDBC supports both!
• Want Virtual Threads?
• Oracle JDBC has been “Virtual Thread
Compatible” since 21.1.0.0
• Want Reactive?
• Oracle R2DBC 1.0.0 is available now
• Consume Flow interfaces directly from
Oracle JDBC’s Reactive Extensions
Copyright © 2022, Oracle and/or its affiliates
Virtual Threads or Reactive?
• Benefits of Virtual Threads:
• Easier to read and write
• Easier to debug
• Integration with JDK tools
• Limitations of Virtual Threads:
• Still a preview feature in JDK 19
• Some libraries are not compatible
Copyright © 2022, Oracle and/or its affiliates
Benefits of Reactive:
• Available now. Supported on JDK 11
• Reactive Libraries (Reactor, RxJava, Akka, Vert.x)
• Stream-like API with a functional style
• Low-level concurrency is handled for you
(locks, atomics, queues).
Limitations of Reactive:
• Steep learning curve
• Harder to read and write
• Harder to debug
Copyright © 2022, Oracle and/or its affiliates
References
• JDK 19 / Project Loom
• JDK 19 - https://openjdk.org/projects/jdk/19/
• Loom - https://openjdk.org/projects/loom/
• JEP 425 Virtual Threads (Preview) - https://bugs.openjdk.org/browse/JDK-8277131
• Introduction to Oracle JDBC 21c Driver Support for Virtual Threads - https://bit.ly/3UlNJWP
• Reactive Streams Ingestion Library
• Getting Started with the Java library for Reactive Streams Ingestion (RSI) -
https://bit.ly/3rEiRnC
• High-throughput stream processing with the Java Library for Reactive Streams Ingestion (RSI),
Virtual Threads, and the Oracle ATP Database - https://bit.ly/3rATCTd
• RSI - https://docs.oracle.com/en/database/oracle/
• R2DBC
• Oracle R2DBC Driver – https://github.com/oracle/oracle-r2dbc
• Develop Java applications with Oracle Database
• JDBC – https://www.oracle.com/database/technologies/appdev/jdbc.html
About me
• Juarez Barbosa Junior - @juarezjunior
• Senior Principal Java Developer Evangelist
• 27 years of experience
• SW Engineering, Developer Relations
• Microsoft, Oracle, IBM, Nokia, Unisys, Accenture, and a
few startups
• Microsoft Azure Developer Relations Lead
• IBM Watson Tech Evangelist & Cloud Rockstar
• IBM Mobile Tech Evangelist & Global Thought Leader
• Nokia Developers Global Champion
• Lead Software/DevOps Architect
• Expertise
• Java, Cloud, DevOps, Cloud-native, Blockchain
Copyright © 2022, Oracle and/or its affiliates
Oracle LiveLabs
Showcasing how Oracle’s solutions can
solve your business problems
500+
free workshops,
available or in
development
3.5 million
people have already visited
LiveLabs
developer.oracle.com/livelabs
learn something new …at your pace!
600+
events run
using LiveLabs
workshops
Create your FREE
Cloud Account
• Go to
https://signup.cloud.oracle.com/
Copyright © 2022, Oracle and/or its affiliates
3 membership tiers
Connect: @oracleace facebook.com/OracleACEs
aceprogram_ww@oracle.com
500+ technical experts &
community leaders helping peers globally
The Oracle ACE Program recognizes & rewards individuals for
their technical & community contributions to the Oracle community
Nominate
yourself or a candidate:
ace.oracle.com/nominate
Learn more - ace.oracle.com
blogs.oracle.com/ace
Thank you!
22
Copyright © 2022, Oracle and/or its affiliates | Confidential: Internal

More Related Content

PDF
DeveloperWeek Europe 2023 - Revolutionize Java DB AppDev with Reactive Stream...
PDF
jPrime 2023 - Revolutionize Java DB AppDev with Reactive Streams and Virtual ...
PDF
CloudTalks - Revolutionize Java DB AppDev with Reactive Streams and Virtual T...
PDF
Cloud Conference Day - Revolutionize Java Database App Development with React...
PDF
CloudLand - Revolutionize Java DB AppDev with Reactive Streams and Virtual Th...
PDF
DWX23 - Revolutionize Java DB AppDev with Reactive Streams and Virtual Threads
PDF
BarcelonaJUG - Revolutionize Java Database Application Development with React...
PDF
Porto Tech Hub Conference 2023 - Revolutionize Java DB AppDev with Reactive S...
DeveloperWeek Europe 2023 - Revolutionize Java DB AppDev with Reactive Stream...
jPrime 2023 - Revolutionize Java DB AppDev with Reactive Streams and Virtual ...
CloudTalks - Revolutionize Java DB AppDev with Reactive Streams and Virtual T...
Cloud Conference Day - Revolutionize Java Database App Development with React...
CloudLand - Revolutionize Java DB AppDev with Reactive Streams and Virtual Th...
DWX23 - Revolutionize Java DB AppDev with Reactive Streams and Virtual Threads
BarcelonaJUG - Revolutionize Java Database Application Development with React...
Porto Tech Hub Conference 2023 - Revolutionize Java DB AppDev with Reactive S...

Similar to TDC Connections 2023 - Revolutionize Java DB AppDev with Reactive Streams and Virtual Threads (20)

PDF
Andersen_Revolutionize Java DB AppDev with Reactive Streams and Virtual Threa...
PDF
AI Industrial Summit - SOFIA, BULGARIA - A High-Speed Data Ingestion Microser...
PDF
BarcelonaJUG - A High-Speed Data Ingestion Service in Java Using MQTT, AMQP, ...
PDF
Melee Numerique 2022 - Revolutionize Java DB App Dev with Reactive Streams an...
PDF
Cloud Conference Day - A High-Speed Data Ingestion Service in Java Using MQTT...
PDF
DWX23 - A High-Speed Data Ingestion Service in Java Using MQTT, AMQP, and STO...
PDF
CloudLand - A High-Speed Data Ingestion Service in Java Using MQTT, AMQP, and...
PDF
DeveloperWeek Latin America 2023 - A High-Speed Data Ingestion Service in Jav...
PDF
Oracle CloudWorld 2023 - A High-Speed Data Ingestion Service in Java Using MQ...
PPTX
R2DBC Reactive Relational Database Connectivity
PDF
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
PDF
Full Steam Ahead, R2DBC!
PDF
ADBA (Asynchronous Database Access)
PDF
JCON OpenBlend Slovenia 2023 - A High-Speed Data Ingestion Service in Java Us...
PDF
Introducing the R2DBC async Java connector
PDF
Quarkus Club_Java Virtual Threads & Pipelined Database Operations
PDF
JDBC Next: A New Asynchronous API for Connecting to a Database
PPTX
Java Database Connectivity by shreyash simu dbce.pptx
PDF
Reactive Relational Database Connectivity
Andersen_Revolutionize Java DB AppDev with Reactive Streams and Virtual Threa...
AI Industrial Summit - SOFIA, BULGARIA - A High-Speed Data Ingestion Microser...
BarcelonaJUG - A High-Speed Data Ingestion Service in Java Using MQTT, AMQP, ...
Melee Numerique 2022 - Revolutionize Java DB App Dev with Reactive Streams an...
Cloud Conference Day - A High-Speed Data Ingestion Service in Java Using MQTT...
DWX23 - A High-Speed Data Ingestion Service in Java Using MQTT, AMQP, and STO...
CloudLand - A High-Speed Data Ingestion Service in Java Using MQTT, AMQP, and...
DeveloperWeek Latin America 2023 - A High-Speed Data Ingestion Service in Jav...
Oracle CloudWorld 2023 - A High-Speed Data Ingestion Service in Java Using MQ...
R2DBC Reactive Relational Database Connectivity
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
Full Steam Ahead, R2DBC!
ADBA (Asynchronous Database Access)
JCON OpenBlend Slovenia 2023 - A High-Speed Data Ingestion Service in Java Us...
Introducing the R2DBC async Java connector
Quarkus Club_Java Virtual Threads & Pipelined Database Operations
JDBC Next: A New Asynchronous API for Connecting to a Database
Java Database Connectivity by shreyash simu dbce.pptx
Reactive Relational Database Connectivity
Ad

More from Juarez Junior (20)

PDF
WeAreDevelopers Berlin - Blazingly Fast GenAI App Development With Java and S...
PDF
WeAreDevelopers Berlin - LangChain4J - A Guide for Impatient Developers
PDF
Build Stuff Lithuania - Blazingly Fast GenAI App Development With Java and Sp...
PDF
DUBJUG-Simplifying Data Access with Jakarta Data for Domain-Driven Design
PDF
Cloud Lunch and Learn -Microsoft Semantic Kernel for Java
PDF
Compass AI Budapest -The Trinity in GenAI - Spring AI, LangChain4J and OpenAI
PDF
GSAS - Global Software Architecture Summit - GenAI-Architectural-Blueprints
PDF
BaselOne_Langchain4J - A Guide for Impatient Developers
PDF
DeveloperWeek USA - A Solid Foundation for GenAI Apps - Exploring Architectur...
PDF
I Love Tech Romania - Blazingly Fast GenAI App Development With Java and Spri...
PDF
I Love Tech Romania - The Trinity in GenAI - Spring AI, LangChain4J and OpenAI
PDF
DUBJUG_Blazingly Fast GenAI App Development With Java and Spring AI.pdf
PDF
DUBJUG_Creating GenAI Apps in Java with SD4J and the ONNX Runtime
PDF
I Love Tech Romania - A High-Speed Data Ingestion Microservice in Java Using ...
PDF
DevTalks Cluj Romania - A Solid Foundation for GenAI Apps.pdf
PDF
Quarkus Club_Revolutionize Java Database App Development with Reactive Stream...
PDF
TDC - The Developers Conference - The Trinity in GenAI - Spring AI, LangChain...
PDF
TDC - The Developers Conference - Creating GenAI Apps in Java with SD4J and t...
PDF
TDC - The Developers Conference - An Introduction to Machine Learning in Java...
PDF
SouJava - Blazingly Fast GenAI App Development With Java and Spring AI
WeAreDevelopers Berlin - Blazingly Fast GenAI App Development With Java and S...
WeAreDevelopers Berlin - LangChain4J - A Guide for Impatient Developers
Build Stuff Lithuania - Blazingly Fast GenAI App Development With Java and Sp...
DUBJUG-Simplifying Data Access with Jakarta Data for Domain-Driven Design
Cloud Lunch and Learn -Microsoft Semantic Kernel for Java
Compass AI Budapest -The Trinity in GenAI - Spring AI, LangChain4J and OpenAI
GSAS - Global Software Architecture Summit - GenAI-Architectural-Blueprints
BaselOne_Langchain4J - A Guide for Impatient Developers
DeveloperWeek USA - A Solid Foundation for GenAI Apps - Exploring Architectur...
I Love Tech Romania - Blazingly Fast GenAI App Development With Java and Spri...
I Love Tech Romania - The Trinity in GenAI - Spring AI, LangChain4J and OpenAI
DUBJUG_Blazingly Fast GenAI App Development With Java and Spring AI.pdf
DUBJUG_Creating GenAI Apps in Java with SD4J and the ONNX Runtime
I Love Tech Romania - A High-Speed Data Ingestion Microservice in Java Using ...
DevTalks Cluj Romania - A Solid Foundation for GenAI Apps.pdf
Quarkus Club_Revolutionize Java Database App Development with Reactive Stream...
TDC - The Developers Conference - The Trinity in GenAI - Spring AI, LangChain...
TDC - The Developers Conference - Creating GenAI Apps in Java with SD4J and t...
TDC - The Developers Conference - An Introduction to Machine Learning in Java...
SouJava - Blazingly Fast GenAI App Development With Java and Spring AI
Ad

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Modernizing your data center with Dell and AMD
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
cuic standard and advanced reporting.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 2 Digital Image Fundamentals.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Cloud computing and distributed systems.
Review of recent advances in non-invasive hemoglobin estimation
Reach Out and Touch Someone: Haptics and Empathic Computing
Modernizing your data center with Dell and AMD
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
madgavkar20181017ppt McKinsey Presentation.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
Advanced methodologies resolving dimensionality complications for autism neur...
Transforming Manufacturing operations through Intelligent Integrations
Dropbox Q2 2025 Financial Results & Investor Presentation
cuic standard and advanced reporting.pdf
Electronic commerce courselecture one. Pdf
Chapter 2 Digital Image Fundamentals.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)

TDC Connections 2023 - Revolutionize Java DB AppDev with Reactive Streams and Virtual Threads

  • 1. Revolutionize Java Database App Development with Reactive Streams and Virtual Threads The Developer’s Conference – TDC Connections 2023 Juarez Barbosa Junior - @juarezjunior March 2023 Copyright © 2022, Oracle and/or its affiliates
  • 2. Agenda • Java App Dev with Oracle Database • Support for the Latest Java Versions • Overview of Oracle DB Access with Java • Oracle JDBC – Sync and Async • Classic Java Platform Threads • Project Loom – Virtual Threads • Virtual Threads - JEP 425 (Preview API) • Demo # 1: Virtual vs Platform Threads • Reactive JDBC - Synchronous vs Asynchronous JDBC • Reactive Streams Ingestion (RSI) • Demo # 2: Reactive Streams Ingestion (RSI) • From Sync to Reactive JDBC: Oracle R2DBC • Demo # 3: Oracle R2DBC • Live Labs/Free Oracle Cloud Account/Oracle ACE Program Copyright © 2022, Oracle and/or its affiliates
  • 3. Copyright © 2022, Oracle and/or its affiliates Java App Dev with Oracle Database
  • 4. Copyright © 2022, Oracle and/or its affiliates Support for the Latest Java Versions • Java 11 - native support, compiled with it • Java 17 - certified • JDBC Standards - 4.2 and 4.3 • JMS 1.1 - latest is 2.0 • GraalVM - native image instrumentation • Reactive Streams - Java Flow API support • Project Loom - Virtual Threads support • Data access is critical in mission-critical apps
  • 5. Copyright © 2022, Oracle and/or its affiliates Overview of Oracle DB Access with Java User Java Code JDBC Reactive Extension Standard JDBC API R2DBC + 3rd party Reactive Streams Libraries Async call with non-blocking backpressure operators (map, reduce, filters), concurrency modeling, monitoring, tracing Implements Java SE reactive stream interface (Flow) Full Reactive Streams Sync/blocking JDBC calls Java Business Logic User Java code Oracle Database Oracle JDBC driver VTs/lightweight JDBC calls
  • 6. Copyright © 2022, Oracle and/or its affiliates Oracle JDBC – Sync and Async ⚫ Reactive Programming − Asynchronous database access with non-blocking network I/O − Oracle R2DBC + Oracle JDBC Reactive Extensions + Oracle Reactive Streams Ingestion − Application call stack must be fully asynchronous − Libraries are here to support it: Reactor, RxJava, Akka, Vert.x ⚫ Project Loom/Virtual Threads − Synchronous database access with lightweight threads − Standard JDBC + Virtual Threads − Client application call stack may use conventional (synchronous) code − Libraries must be compatible with Virtual Threads − Oracle instrumented the Oracle JDBC 21c driver to support Virtual Threads
  • 7. Copyright © 2022, Oracle and/or its affiliates Classic Java Platform Threads ⚫ Blocking Threads ⚫ A JDBC call blocks a thread for 100’s of milliseconds (thread-per-request style) ⚫ Thread count increases linearly with the number of JDBC calls ⚫ Performance degrades as the number of threads increases ⚫ 1 MB of stack memory per thread ⚫ Scheduling many platform threads is expensive ⚫ Preemptive scheduling vs time-slicing
  • 8. Copyright © 2022, Oracle and/or its affiliates Virtual Threads - JEP 425 (Preview API) ⚫ Virtual Threads ⚫ Lightweight threads that dramatically reduce the effort of writing, maintaining, and observing high-throughput concurrent applications ⚫ Enable applications written in the simple thread-per-request style to scale with near- optimal hardware utilization ⚫ Enable existing code that uses the java.lang.Thread API to adopt virtual threads with minimal change ⚫ Enable easy troubleshooting, debugging, and profiling of virtual threads with existing JDK tools ⚫ Do not remove the traditional implementation of threads ⚫ Do not alter the basic concurrency model of Java
  • 9. Copyright © 2022, Oracle and/or its affiliates Demo # 1: Virtual vs Platform Threads ⚫ Virtual Threads versus Platform Threads ⚫ JEP 425 Virtual Threads (Project) ⚫ Runs on Java 19 (Preview API) ⚫ javac --release 19 --enable-preview ⚫ java --enable-preview ⚫ Comparison of OS resources consumption (Threads only + JDBC) ⚫ Oracle JDBC Driver 21c instrumented to support Virtual Threads ⚫ API is Oracle JDBC with the Java SE library (Executor, ThreadFactory)
  • 10. Copyright © 2022, Oracle and/or its affiliates Reactive JDBC - Synchronous vs Asynchronous JDBC Setup Blocking Handle Result Setup Non-Blocking Handle Result Synchronous JDBC Setup Blocking Handle Result Setup Non-Blocking Handle Result Setup Non-Blocking Handle Result Reactive JDBC Database Setup Blocking Handle Result Database
  • 11. Copyright © 2022, Oracle and/or its affiliates Reactive Streams Ingestion (RSI) ⚫ Java Library for Reactive Streams Ingestion ⚫ Streaming capability: Ingest data in an unblocking, and reactive way from a large group of clients ⚫ Group records through RAC (Real App Clusters), and Shard affinity using native UCP (Universal Connection Pool) ⚫ Optimize CPU allocation while decoupling record Processing from I/O ⚫ Fastest insert method for the Oracle Database through Direct Path Insert, bypassing SQL and writing directly into the DB files
  • 12. Copyright © 2022, Oracle and/or its affiliates Demo # 2: Reactive Streams Ingestion (RSI) Container Pipelines, Jenkins, etc. Build Test Push Push Docker images to Registry Cloud Infrastructur e Registry Container Engine for Kubernetes Pull images from Registry Deploy images to production Kubernetes worker nodes Containers running microservices deployed over Kubernetes ORACLE CLOUD INFRASTRUCTURE ATP, ADW, ATP-D, AFDW-D Memoptimized Rowstore RSI Runtime: Non- blocking, optimized library for streaming data through Direct Path, Shard & RAC/FAN support. HTTP / REST Engine over Helidon Define build for CI/CD toolchain gRPC / AMQP / MQTT Engines Microservices Files / Logs IoT Devices / Apps cv MQTT gRPC AMQP HTTP / REST JDBC Direct Path INSERT Record Streaming over multiple protocols.
  • 13. Copyright © 2022, Oracle and/or its affiliates From Sync to Reactive JDBC: Oracle R2DBC static String queryJdbc(java.sql.Connection connection) throws SQLException { try (java.sql.Statement statement = connection.createStatement()) { ResultSet resultSet = statement.executeQuery("SELECT * FROM CUSTOMERS"); if (resultSet.next()) return resultSet.getString(1); else throw new NoSuchElementException("Query returned zero rows"); } } static Publisher<String> queryR2dbc(io.r2dbc.spi.Connection connection) { return Flux.from(connection.createStatement( "SELECT * FROM CUSTOMERS") .execute()) .flatMap(result -> result.map(row -> row.get(0, String.class))) .switchIfEmpty(Flux.error( new NoSuchElementException("Query returned zero rows"))); }
  • 14. Copyright © 2022, Oracle and/or its affiliates Demo # 3: Oracle R2DBC ⚫ Oracle Reactive Relational Database Connectivity (R2DBC) ⚫ Oracle R2DBC Driver is a Java library that supports reactive Programming with Oracle Database ⚫ It implements the R2DBC Service Provider Interface (SPI) as specified by the Reactive Relational Database Connectivity (R2DBC) ⚫ The R2DBC SPI exposes Reactive Streams as an abstraction for Remote database operations ⚫ The sample code uses Project Reactor. It could use RxJava, Akka, or any RS library ⚫ Runs on Java 11+
  • 15. Virtual Threads or Reactive? • Oracle JDBC supports both! • Want Virtual Threads? • Oracle JDBC has been “Virtual Thread Compatible” since 21.1.0.0 • Want Reactive? • Oracle R2DBC 1.0.0 is available now • Consume Flow interfaces directly from Oracle JDBC’s Reactive Extensions Copyright © 2022, Oracle and/or its affiliates
  • 16. Virtual Threads or Reactive? • Benefits of Virtual Threads: • Easier to read and write • Easier to debug • Integration with JDK tools • Limitations of Virtual Threads: • Still a preview feature in JDK 19 • Some libraries are not compatible Copyright © 2022, Oracle and/or its affiliates Benefits of Reactive: • Available now. Supported on JDK 11 • Reactive Libraries (Reactor, RxJava, Akka, Vert.x) • Stream-like API with a functional style • Low-level concurrency is handled for you (locks, atomics, queues). Limitations of Reactive: • Steep learning curve • Harder to read and write • Harder to debug
  • 17. Copyright © 2022, Oracle and/or its affiliates References • JDK 19 / Project Loom • JDK 19 - https://openjdk.org/projects/jdk/19/ • Loom - https://openjdk.org/projects/loom/ • JEP 425 Virtual Threads (Preview) - https://bugs.openjdk.org/browse/JDK-8277131 • Introduction to Oracle JDBC 21c Driver Support for Virtual Threads - https://bit.ly/3UlNJWP • Reactive Streams Ingestion Library • Getting Started with the Java library for Reactive Streams Ingestion (RSI) - https://bit.ly/3rEiRnC • High-throughput stream processing with the Java Library for Reactive Streams Ingestion (RSI), Virtual Threads, and the Oracle ATP Database - https://bit.ly/3rATCTd • RSI - https://docs.oracle.com/en/database/oracle/ • R2DBC • Oracle R2DBC Driver – https://github.com/oracle/oracle-r2dbc • Develop Java applications with Oracle Database • JDBC – https://www.oracle.com/database/technologies/appdev/jdbc.html
  • 18. About me • Juarez Barbosa Junior - @juarezjunior • Senior Principal Java Developer Evangelist • 27 years of experience • SW Engineering, Developer Relations • Microsoft, Oracle, IBM, Nokia, Unisys, Accenture, and a few startups • Microsoft Azure Developer Relations Lead • IBM Watson Tech Evangelist & Cloud Rockstar • IBM Mobile Tech Evangelist & Global Thought Leader • Nokia Developers Global Champion • Lead Software/DevOps Architect • Expertise • Java, Cloud, DevOps, Cloud-native, Blockchain Copyright © 2022, Oracle and/or its affiliates
  • 19. Oracle LiveLabs Showcasing how Oracle’s solutions can solve your business problems 500+ free workshops, available or in development 3.5 million people have already visited LiveLabs developer.oracle.com/livelabs learn something new …at your pace! 600+ events run using LiveLabs workshops
  • 20. Create your FREE Cloud Account • Go to https://signup.cloud.oracle.com/ Copyright © 2022, Oracle and/or its affiliates
  • 21. 3 membership tiers Connect: @oracleace facebook.com/OracleACEs [email protected] 500+ technical experts & community leaders helping peers globally The Oracle ACE Program recognizes & rewards individuals for their technical & community contributions to the Oracle community Nominate yourself or a candidate: ace.oracle.com/nominate Learn more - ace.oracle.com blogs.oracle.com/ace
  • 22. Thank you! 22 Copyright © 2022, Oracle and/or its affiliates | Confidential: Internal