配置 Apache Cayenne 以异步方式与 Vertx 一起使用
Configure Apache Cayenne to be used in an asynchronous manner with Vertx
我将 Apache Cayenne 与 Vertx 一起使用。 Vertx 依赖于一切都是异步的,它会主动寻找阻塞的线程。
所以执行类似...
List<Artist> artists = ObjectSelect.query(Artist.class).select(context);
...将导致 Vertx 抱怨以下内容:
WARNING: Thread Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 4750 ms, time limit is 2000
请注意,实际上有一些方法可以通过将代码包装在 executeBlocking
函数中来解决这个问题,如下所示:
// 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
})
然而,像这样继续包装我的 ORM 函数变得很痛苦。
我想知道是否有标志或开关可以将 Cayenne 异步化?或者,如果没有这样的标志,我想知道是否有办法使用 Postgres Async Driver by Mauricio. I pick that specific async driver because Vertx provides native support for it.
抱歉,没有使 Cayenne 异步的神奇开关。 Cayenne 在内部严重依赖 JDBC,而后者又是同步的(并且可能永远如此,请参阅很好的讨论 here)。
此外,对 JDBC 的依赖使得使用 non-jdbc 驱动程序变得非常困难,所以这里也不走运。
因此,适合您环境的自定义包装器似乎是您最好的(如果不是唯一的)选择。
我将 Apache Cayenne 与 Vertx 一起使用。 Vertx 依赖于一切都是异步的,它会主动寻找阻塞的线程。
所以执行类似...
List<Artist> artists = ObjectSelect.query(Artist.class).select(context);
...将导致 Vertx 抱怨以下内容:
WARNING: Thread Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 4750 ms, time limit is 2000
请注意,实际上有一些方法可以通过将代码包装在 executeBlocking
函数中来解决这个问题,如下所示:
// 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
})
然而,像这样继续包装我的 ORM 函数变得很痛苦。
我想知道是否有标志或开关可以将 Cayenne 异步化?或者,如果没有这样的标志,我想知道是否有办法使用 Postgres Async Driver by Mauricio. I pick that specific async driver because Vertx provides native support for it.
抱歉,没有使 Cayenne 异步的神奇开关。 Cayenne 在内部严重依赖 JDBC,而后者又是同步的(并且可能永远如此,请参阅很好的讨论 here)。
此外,对 JDBC 的依赖使得使用 non-jdbc 驱动程序变得非常困难,所以这里也不走运。
因此,适合您环境的自定义包装器似乎是您最好的(如果不是唯一的)选择。