有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

MongoDB的Spring数据中的java非阻塞查询?

我想通过使用MongoDB's Async Client API访问MongoDB的Spring数据执行非阻塞数据库查询

到目前为止,我只看到了返回

  • java.util.concurrent.Future
  • java.util.concurrent.CompletableFuture
  • org.springframework.util.concurrent.ListenableFuture

并用@Async注释查询方法,例如

public interface UserRepo extends Repository<User, Long> {

  @Async
  ListenableFuture<User> findByName(String name);

}

但是documentation明确指出实际的[...] query execution will occur in a task that has been submitted to a Spring TaskExecutor。所以它不是真正的无阻塞,而是使用一个扩展性不好的线程池来解耦我的线程

因此,我的问题是:

如何使用MongoDB异步驱动程序的NIO功能在非阻塞模式下执行查询

到目前为止,我看到的唯一解决方法是摆脱Spring数据,并使用Mongo Async Driver API实现自己的数据库查询。但我希望我只是错过了一些东西,而且有一个非常正面的答案


共 (1) 个答案