2. Juarez Barbosa Junior - @juarezjunior
• Sr. 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, Blockchain
About me
3. Java App Dev with Oracle Database
• Language Comprehensive Programming Language and Framework Support
• Mission Critical Simple Mission Critical Application Development
• Cloud-native Seamless cloud-native application development
• IDE Support Plugins for popular IDEs with Oracle Database and OCI support
Oracle Database
4. Summary 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
5. ⚫ 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
Two Solutions : Oracle JDBC Supports Both
6. ⚫ 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 on a single CPU is expensive
⚫ Reactive Programming
⚫ Multiple threads are required when handling an async request
⚫ Async calls are executed in different threads -> hard to debug them
⚫ Paradigm shift requires upskilling efforts
⚫ Hard to maintain
The Problem: Classic Java Platform Threads
7. The Solution: Virtual Threads
⚫ JEP 425: Virtual Threads (JDK 19 - Preview API)
⚫ Lightweight threads that dramatically reduce the effort of writing, maintaining, and observing
high-throughput concurrent applications
⚫ VTs enable applications written in the simple thread-per-request style to scale with near-
optimal hardware utilization
⚫ VTs enable existing code that uses the java.lang.Thread API to adopt virtual threads with
minimal change
⚫ VTs enable easy troubleshooting, debugging, and profiling of virtual threads with existing JDK
tools
⚫ VTs do not remove the traditional implementation of threads
⚫ VTs do not alter the basic concurrency model of Java
8. ⚫ Demo #1: Virtual Threads
− Oracle JDBC Driver 21c instrumented to support Virtual Threads
− API is Oracle JDBC with the Java SE library (Executor, ThreadFactory)
− JEP 425 Virtual Threads (Project Loom – Preview API)
− Runs on Java 19
Demos
9. 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
10. From Synchronous to Reactive JDBC: Query
static String queryJdbc(java.sql.Connection connection) throws
SQLException {
try (java.sql.Statement statement = connection.createStatement()) {
ResultSet resultSet =
statement.executeQuery("SELECT 'Hello, JDBC!' FROM sys.dual");
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 'Hello, R2DBC!' FROM sys.dual")
.execute())
.flatMap(result ->
result.map(row -> row.get(0, String.class)))
.switchIfEmpty(Flux.error(
new NoSuchElementException("Query returned zero rows")));
}
11. ⚫ Demo #1: Reactive JDBC
− API is Oracle R2DBC with a reactive streams library
− Demo uses Project Reactor. Could use RxJava, Akka, or any RS library
− Runs on Java 11+
Demos
14. Reactive Streams Ingestion Library
Java Program
Reactive Streams Ingestion Library
Direct Path Insert
Thread Scheduling
Record Grouping and Routing
UCP Pooling and
Routing (Shard &
Rac)
1
2
3
4
15. ⚫ Demo #3: Reactive Streams Ingestion Library
− API is Oracle Reactive Streams Ingestion Library
− Leverages Oracle Direct Path Insert
− Optimized CPU allocation
− Record Grouping and Routing
Demos
16. Poll
Pick one or more options that may describe your situation:
• Not concerned by thread counts/throughput
• Not using reactive, waiting for Project Loom (Virtual Threads)
• Interested in, or already using a reactive framework (Reactor, RxJava)
• Interested in, or already using R2DBC
• Interested in, or already using Oracle JDBC Reactive Extensions
• Interested in, or already using Oracle Reactive Streams Ingestion (RSI)