Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 2
But... • What do you do if application requires high throughput? • What if does the application run standalone as an AOT compiled native image or a function? 8 !
Asynchronous Database Access (ADBA) • Being developed by the JDBC Expert Group with community input • Targeted for a near future release of Java • Asynchronous apps have better throughput – Fewer threads means less thread scheduling, less thread contention – Database access is slow so blocked threads leave resources idle for a long time – Simultaneous access to multiple databases (map/reduce, sharded databases, ...) – Fire and forget (DML, stored procedures, ...) 10 Java standard database access API that never blocks user threads
Goals • No user thread blocks – Minimize the number of threads used for database access • Alternate API for database access – Not an extension of the standard JDBC API – Not a replacement for the standard JDBC API • Target high throughput apps – Not a completely general purpose database access API – The initial version will have a limited feature set • Build on the Java SE class library 11
Goals • No user thread blocks – Minimize the number of threads used for database access • Alternate API for database access – Not an extension of the standard JDBC API – Not a replacement for the standard JDBC API • Target high throughput apps – Not a completely general purpose database access API – The initial version will have a limited feature set • Build on the Java SE class library 12 Neither replacement nor enhancement, but complementary
Design choices • Minimal or no reference to java.sql • Rigorous use of types • Builder pattern • Fluent API • Immutable after initialization • One way to do something is enough • Avoid SQL processing • Avoid callback hell 13
ADBA (Asynchronous Database Access) • Package –java.sql2 (jdk.incubator.sql2) • Module –jdk.adba (jdk.incubator.adba) [Note] • Implementation-specific features are out of scope of this session. – Statement cache – Connection cache... 14
What About... ? • Streams – Java streams are inherently synchronous • Reactive Streams – Not integrated into the Java SE class library • Node.js – JavaScript... (Indeed this runs on Graal VM, but...) • ADBCJ - Asynchronous Database Connectivity in Java (ADBCJ) https://code.google.com/archive/p/adbcj/ 16 There are already multiple asynchronous/non-blocking Java and JavaScript APIs...
CompletionStage & CompletableFuture • Java class library mechanism for asynchronous style programming – Brings reactive programming to Java – Enables the composition of asynchronous tasks – A task has a state and it might be... • running • completed normally with a result • completed exception all with an exception – Event thread : the result of the completion is pushed to dependent tasks • Push model à higher scalability than pull or poll • Supports lambda expressions and fluent programming 18
Execution Model (1/2) • Operation consists of a result and a CompletionStage • SQL or other database operation • Parameter assignments • Result handling • Submission and CompletableFuture 19 Everything is an Operation
Execution Model (2/2) • User thread creates and submits Operations – User thread is never blocked when creating and submitting Operations. • Implementation executes those Operations asynchronously – Performs round trip(s) to the database – Executes result handling – Completes CompletableFutures 20
All SQL is Vendor Specific • No escape sequences • No specified parameter markers • Non vendor specific syntax requires processing by the driver – Adds overhead – Increases code complexity – Minimal benefit as most apps are tied to a specific database regardless 23
All SQL is Vendor Specific • DB2 (:foo) • MySQL (?) • Oracle Database (:foo) • PostgresSQL ($1) • SQL Server (@foo) 24 Note: Code examples use parameter markers from a variety of databases.
Connection Pooling in interface Connection: public Connection activate(); public Connection deactivate(); public registerLifecycleListener(LifecycleListener listener); 28 If you remove registered LifecycleListener, call deregisterLifecycleListener()
OperationGroup (1/2) • OperationGroup has its own result handling and CompletableFuture • Members submitted to group.OperationGroup is submitted as a unit • Execution Order – Default : Sequential in order submitted – parallel() : should be marked if having member Operations executed in any order including in parallel. 32 group of Operations
OperationGroup (1/2) • Error response – Default : Skip remaining group members if failure of one member Operation happens. (with a SqlSkippedException with the cause set to the original exception). – independent(): should be marked if remaining group members unaffected • Conditional or unconditional • Connection is an OperationGroup – Sequential, dependent, unconditional by default 33
Close in interface Connection: public default void close() { closeOperation().submit(); releaseProhibitingMoreMembers(); } 39 CloseOperation is never skipped.
40 public static class NlsLanguageProperty implements ConnectionProperty { public static final ConnectionProperty NLS_LANGUAGE = new NlsLanguageProperty(); private NlsLanguageProperty() { } public String name() { return "NLS_LANGUAGE"; } public Class range() { return String.class; } ConnectionProperty (1/2)
Key takeaways • Asynchronous • Geared toward high-throughput programs • Does not attempt to support every database feature • Does not attempt to abstract the database • Uses the builder pattern • Supports the fluent programming style 48
Status • Now developed by the JDBC Expert Group through the Java Community Process • Targeted for a near future release of Java • Send feedback to [email protected] 49 Everything is subject to change!
Resources • Available for download from OpenJDK http://oracle.com/goto/java-async-db • AoJ (ADBA over JDBC) [JDK 9 or later is required] https://github.com/oracle/oracle-db-examples/tree/master/java/AoJ • JavaDoc http://cr.openjdk.java.net/~lancea/8188051/apidoc/jdk.incubator.adba-summary.html 50
Safe Harbor Statement The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 51