ormlite-jdbc icon indicating copy to clipboard operation
ormlite-jdbc copied to clipboard

Asynchronous JDBC

Open noordawod opened this issue 5 years ago • 5 comments

For example, can ormlite adapt to working with this library: https://github.com/jasync-sql/jasync-sql

But in general, how much work would it take to transform the library to both sync and async?

noordawod avatar Jan 06 '20 11:01 noordawod

Hrm. Interesting. The idea is to have a thread pool and return futures for any operations that block?

j256 avatar Jan 06 '20 16:01 j256

Well, that's one way to do it since the current JDBC blocks.

Another way I thought about would be a combination of a thread pool and query queue. Although there will be limited number of threads (maybe per CPU threads), the query queue can grow to include thousands of queries.

And of course, there are Kotlin's coroutines -- could be also adapted to work in Java.

Finally, Oracle talked about ADBA back in 2016 (https://github.com/oracle/oracle-db-examples/tree/master/java/AoJ) so I suppose asynchronousity is, or will be, a reality soon enough.

noordawod avatar Jan 07 '20 07:01 noordawod

Coroutines are a great way to tackle this issue, I think, and luckily there's a pure Java implementation for it: https://github.com/esoco/coroutines

noordawod avatar Jan 07 '20 11:01 noordawod

I really don't want to add that as a dependency @noordawod . Is there something we can do to simulate it? What are the pattern(s) that we are trying to support?

j256 avatar Jan 08 '20 22:01 j256

If not coroutines, then I guess an Executor with a query queue. It should be straightforward as the existing code doesn't change, but we add a new ormlite-jdbc-async that orchestrates the asynchronousity. What do you think?

About patterns: I would say callback-based pattern at this point, the easiest.

noordawod avatar Jan 13 '20 10:01 noordawod