0

I'm using Apache Cayenne with Vertx. Vertx relies on everything to be asynchronous and it actively looks for threads that block.

So performing something like...

List<Artist> artists = ObjectSelect.query(Artist.class).select(context);

...will result in Vertx complaining with the following:

WARNING: Thread Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 4750 ms, time limit is 2000

Please note that there are in fact ways to get around this by wrapping the code in an executeBlocking function as follows:

// Turning synchronous code to async in Vertx
vertx.executeBlocking<Any>({ future ->
     List<Artist> artists = ObjectSelect.query(Artist.class).select(context)
     future.complete(artists)
}, { res ->
     // The result
})

However, it becomes a pain to keep wrapping my ORM functions like that.

I wonder if there's a flag or a switch to turn Cayenne asynchronous? Or, if there isn't such a flag, I wonder if there's a way to use the Postgres Async Driver by Mauricio. I pick that specific async driver because Vertx provides native support for it.

gurpreet-
  • 509
  • 8
  • 18
  • This an Apache Cayenne question so just leaving this as a comment: why not package your db service as a worker verticle? You'd get rid of the blocked thread warning and could easily scale up/out by exposing this service other the eventbus. – tsegismont Mar 12 '18 at 13:56
  • That's a great suggestion. If I communicate via the event bus with the vertx cayenne verticle then I assume I would need to create an abstraction layer over the event bus to communicate with the ORM? – gurpreet- Mar 13 '18 at 08:42
  • 1
    You could use [Vert.x Service Proxies](http://vertx.io/docs/vertx-service-proxy/java/) – tsegismont Mar 13 '18 at 09:43

1 Answers1

1

Sorry, there is no magic switch to make Cayenne async. Cayenne internally relies heavily on JDBC, which in it's turn is synchronous (and probably will be forever, see good discussion here).

Moreover dependency on JDBC makes it really hard to use non-jdbc drivers, so no luck here too.

So custom wrapper suitable for your environment seems your best (if not only) option.

Nikita
  • 266
  • 2
  • 7
  • There is some talk about an [async JDBC from Oracle](https://www.reddit.com/r/java/comments/7464zn/asynchronous_jdbc_api_in_the_works/) which is stated for release in JDK 10, so hopefully they get that working in time. – gurpreet- Mar 13 '18 at 09:36