Quarkus Club_Java Virtual Threads & Pipelined Database Operations

juarezjunior 26 views 33 slides Mar 11, 2025
Slide 1
Slide 1 of 33
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33

About This Presentation

Quarkus Club_Java Virtual Threads & Pipelined Database Operations


Slide Content

Java Virtual Threads & Pipelined Database
Operations
Quarkus Club
Juarez Barbosa Junior @juarezjunior
Senior Principal Java Developer Evangelist
ORACLE
Copyright © 2024, Oracle and/or its affiliates

Juarez Barbosa Junior
Senior Principal Java Developer Evangelist @ Oracle
•Speaking from Dublin, Ireland
•28 years of experience in SW Engineering & DevRel
•Oracle, Microsoft, IBM, Nokia, Unisys, Accenture, startups
•Microsoft Azure Developer Relations Lead
•IBM Watson Tech Evangelist & Cloud Rockstar
•IBM Mobile Tech Evangelist & Global Thought Leader
•Nokia Developers Global Champion
•Java, Python, Cloud, DevOps, SRE, Cloud-native, IoT, AI, Blockchain,
Rust
•Speaker at conferences
•Oracle CloudWorld, Oracle Code, Microsoft Ignite & TechX, jPrime,
JCON, DevConf.cz, GeeCon, DevOpsDays, DeveloperWeek, DevOps
Institute, CloudLand, DWX, The Developer’s Conference (TDC),
Sec4Dev, JSNation, NodeConf, Conf42, Shift Conf, Global Azure,
Open-Source Lisbon, CodeFrenzy, Mêlée Numérique, React Summit,
Test.js Summit, Porto TechHub Conf, Pyjamas, MiTechCon, Data
Science Summit, OpenSourceNorth, WeAreDevelopers, Global
Software Architecture Summit, JavaCro, JUGs, OUGs, GDGs,
meetups, hackathons, and customer engagements.
@juarezjunior
@juarezjunior

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Agenda
•Java App Dev with the Oracle Database
•Oracle JDBC -Support for the Latest Java Versions
•Overview of Oracle DB Access with Java
•Pipelined Database Operations, Oracle AI Vector Search
•Demo #4: Structured Concurrency + Pipelined Database
Operations + AI Vector Search
•Live Labs/Free Oracle Cloud Account/Oracle ACE Program
Copyright © 2024, Oracle and/or its affiliates

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Java App
Dev with
Oracle
Database
Copyright © 2024, Oracle and/or its affiliates

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Overview of Oracle DB Access with Java
Copyright © 2024, Oracle and/or its affiliates

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Copyright © 2024, Oracle and/or its affiliates
Pipelined Database Operations
Before Pipelined Database Operations
The server must complete the processing
of the request and sending the response
before accepting another request
The client and server have idle time
The Java app sends
a request
The server sends
the response
The Java app
receives
the response

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Copyright © 2024, Oracle and/or its affiliates
Pipelined Database Operations
With Pipelining
No-Blocking Requests and Responses
Send multiple requests from client to server
without waiting for responses
Application can asynchronously perform
other operations
The server processes the requests in order
and sends the responses back to the client
when ready, in the same order they
were received
Benefits
Improved response time and throughput
Particularly useful when network latency is high

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Copyright © 2024, Oracle and/or its affiliates
Pipelined Database Operations
Performance Improvements depending on the CPU load, the workload
profiles on the server side, and the network latency between client and server
•Up to 90% improvement for queries only workload over a fast network
•Up to 90x improvement for queries only workload over a slow network
•Up to 24% improvement for OLTP workload over a fast network
•Up to 7x improvement for OLTP workload over a slow network
•Up to 100+x improvement for DML workload
The Oracle JDBC Driver 23aisupports Pipelined Database Operations through:
•The Oracle JDBC Reactive Extensions
•Reactive Streams libraries
•Java Virtual Threads
•Structured Concurrency
•The Standard JDBC Batching API

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Copyright © 2024, Oracle and/or its affiliates
JDBC Reactive Extensions and Pipelined DB Operations

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Copyright © 2024, Oracle and/or its affiliates
R2DBC and Pipelined Database Operations

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Copyright © 2024, Oracle and/or its affiliates
Structured Concurrency and Java Virtual Threads
Structured concurrency treats groups of related tasks running in different threads as a single unit of work,
thereby streamlining error handling and cancellation, improving reliability, and enhancing observability.
•The StructuredTaskScopeclass enables you
coordinate a group of concurrent subtasks as a unit.
With a StructuredTaskScope instance, you fork each
subtask, which runs them in their own individual
thread. After, you join them as a unit.
•As a result, the StructuredTaskScope ensures that
the subtasks are completed before the main task
continues.
•Alternatively, you can specify that the application
continues when one subtask succeeds.

Confidential - Oracle Restricted
Confidential - Oracle Restricted
New| Oracle Database 23ai
Next-Generation Converged Database Services
Over300 major new features plusthousands of enhancements
Available on OCI and Azure
Major focus on
•AI for Data features
•Developer/Analyst features
•Mission-Critical features
Addresses data management pain points that have frustrated customers forever
Copyright © 2024, Oracle and/or its affiliates

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Oracle Database 23ai -AI for Data
Algorithmic AI AI Vector Search Augmented Generative AI (LLMs)
Distributed AI AI Storage AI Developer Tools
Copyright © 2024, Oracle and/or its affiliates

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Oracle Database 23ai -Dev for Data
JSON Relational
Duality Views
Property Graph Views
JavaScript
Stored Procedures
Data Intent
Language
Lock-free Consistent Updates,
Long-running Transactions
True
Cache
Copyright © 2024, Oracle and/or its affiliates

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Oracle Database 23ai -Mission-Critical Data
RAFT Replication for
Globally Distributed Database
In-Database
Firewall
Real-Time SQL Plan
Management
RAC, Exadata, Data Guard
Simplicity and Scalability
Analytic SQL
Simplicity and Scalability
Priority
Transactions
Copyright © 2024, Oracle and/or its affiliates

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Free| Oracle Database 23ai For Developers
Oracle Always Free ADB
Available on OCI
ADB Free Container Image
Available for download
Oracle Database Free
Available as RPM, Docker
Image, VBox VM
Copyright © 2024, Oracle and/or its affiliates | Confidential -Internal
Very Low Cost Supported DeveloperEdition of ADB, BaseDB, ExaDB-D, and ExaDB-C@C

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Copyright © 2024, Oracle and/or its affiliates
LLMs, Oracle DB 23ai, Oracle AI Vector Search and
Vector Embeddings
1-Gather and pre-process
the target dataset
(Texts/Documents
Images, Audio)
3-The LLM learns patterns and
relationships within the data.
LLM
2-Feed LLM with
the pre-processed
data. 33
42
16
21
50
33
42
16
21
50
4-The LLM generates
Embedding Vectors
•GPT-4
•Cohere Command-R
•Llama 3
•Others

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Copyright © 2024, Oracle and/or its affiliates
LLMs, Oracle DB 23ai, Oracle AI Vector Search and
Vector Embeddings
LLM
33
42
16
21
50
33
42
16
21
50
5-Embedding Vectors stored in Oracle database
along with the original texts.

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Copyright © 2024, Oracle and/or its affiliates
Demo #4: Structured Concurrency + Pipelined Database
Operations + Oracle AI Vector Search
Combining Structured Concurrency + Pipelined Database Operations +
Oracle AI Vector Search
•Create a database table
•Populate the database
•Update the database table with vector embeddings
•Perform vector similarity searches

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Copyright © 2024, Oracle and/or its affiliates
Demo #4: Structured Concurrency + Pipelined Database
Operations + Oracle AI Vector Search
Text +
Vector
Embeddings
2-Update the Text table with
corresponding Vector
Embedding fromOracle
Cloud’s
Generative AI service
1-Stream text from a
book about animals
into a table
3-Perform similarities
Searches for search
terms
Demo code @ https://tinyurl.com/nbjmczjr
Oracle Database 23ai FREE

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Copyright © 2024, Oracle and/or its affiliates
Demo #4: Structured Concurrency + Pipelined Database
Operations + AI Vector Search
Create and populate the DB table
loadTable(Connection): loads a database table with text data.
Stream Text from book URL
Concurrent batch inserts with StructuredTaskScope
Pipeline batch insert (id, Text) into the table

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Copyright © 2024, Oracle and/or its affiliates
Demo #4: Structured Concurrency + Pipelined Database
Operations + AI Vector Search
Update the Table with Embeddings
updateTable(Connection): store vector Embeddings for the text data.
Pipeline row fetches ( id, Text) from table where Embeddings IS NULL
Request Embeddings from Oracle Cloud's Generative AI service
Pipeline batch update with Embeddings

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Copyright © 2024, Oracle and/or its affiliates
Demo #4: Structured Concurrency + Pipelined Database
Operations + AI Vector Search
Perform Similarities Search 1/2
Perform vector similarity searches
with the following prompts:
•Predatory behavior of cats
•Location of bears
•Best climate for dogs
•Animals in ancient times
•Beautiful birds
•Deadly fish
•Where the wild things are

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Copyright © 2024, Oracle and/or its affiliates
Demo #4: Structured Concurrency + Pipelined Database
Operations + AI Vector Search
Perform Similarities Search 2/2
searchTableText(Connection, List):
Perform a similarity search against vector embeddings
Convert Search Terms to Vector Embeddings
Pipeline queries with VECTOR_DISTANCE on Virtual Threads as it allows for concurrent progress of
MANY statements from one (1) JDBC connection
SELECT text
FROM example
ORDER BY VECTOR_DISTANCE(embedding, ?, COSINE)
FETCH APPROX FIRST 1 ROW ONLY
Return Similarity Search Results

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Copyright © 2024, Oracle and/or its affiliates
Demo #4: Structured Concurrency + Pipelined Database
Operations + AI Vector Search
Perform Similarities Search 2/2

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Virtual Threads or Reactive?
•Oracle JDBC supports both!
•Want Virtual Threads?
•The Oracle JDBC driver is Virtual Thread compatible
•Pipelined Database Operations
•Want Reactive?
•Oracle R2DBC, Oracle RSI, Oracle JDBC Reactive Extensions
•Pipelined Database Operations
Copyright © 2024, Oracle and/or its affiliates

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Virtual Threads or Reactive?
•Benefits of Virtual Threads:
•Easier to read and write
•Easier to debug
•Integration with JDK tools
•Do not alter the basic concurrency model of Java
•Now available in JDK 21 / 22
•Limitations of Virtual Threads:
•Some libraries/frameworks are not
compatible yet
Copyright © 2024, Oracle and/or its affiliates
Benefits of Reactive:
•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

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Copyright © 2024, Oracle and/or its affiliates
Technical References
•JDK 22
•The Arrival of JDK 22 -https://blogs.oracle.com/java/post/the-arrival-of-java-22
•Virtual Threads
•JEP 444 Virtual Threads -https://openjdk.org/jeps/444
•JEP 480 Structured Concurrency (Third Preview) -https://openjdk.org/jeps/480
•Introduction to Oracle JDBC 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
•A High-Speed Data Ingestion Solution in Java Using MQTT, AMQP, and STOMP -
https://medium.com/oracledevs/a-high-speed-data-ingestion-microservice-in-java-using-mqtt-
amqp-and-stomp-135724223ae1
•R2DBC
•Getting Started with Reactive Relational Database Connectivity and the Oracle R2DBC Driver –
http://rb.gy/95u5f8
•Pipelined Database Operations -https://rb.gy/k57g3r
•Generative AI Service -Oracle Cloud Infrastructure (OCI) –https://rb.gy/a9k69e
•What’s in Oracle Database 23ai for Java Developers?
•https://www.oracle.com/a/tech/docs/database/whats-in-oracledb23ai-for-java-developers.pdf

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Oracle LiveLabs
Showcasing how Oracle’s solutions can
solve yourbusiness 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

3 membership tiers
Connect: @oracleace facebook.com/[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

Confidential - Oracle Restricted
Confidential - Oracle Restricted
Create your FREE
Cloud Account
•Go to
https://signup.cloud.oracle.com/
Copyright © 2024, Oracle and/or its affiliates

Juarez Junior
@juarezjunior