Java Spring Cassandra存储库-在后台线程中保存记录
我一直在用后台线程在数据库中创建记录,但在控制台中没有得到任何响应—没有错误、异常或日志 下面是代码 在我的spring组件中,我有:Java Spring Cassandra存储库-在后台线程中保存记录,java,spring,cassandra,Java,Spring,Cassandra,我一直在用后台线程在数据库中创建记录,但在控制台中没有得到任何响应—没有错误、异常或日志 下面是代码 在我的spring组件中,我有: ExecutorService tPool = Executors.newFixedThreadPool(15); //This is a repository that extends CassandraRepository @Autowired MyRepository myRepository; CompletableFuture<Boolean
ExecutorService tPool = Executors.newFixedThreadPool(15);
//This is a repository that extends CassandraRepository
@Autowired
MyRepository myRepository;
CompletableFuture<Boolean> myBool = CompletableFuture.supplyAsync(() -> {
//processing here
return new doSomeProcessing(arg1, arg2, arg3).process();
}, tPool);
myBool.whenComplete((isTrue, throwThis) -> {
if(isTrue) {
// do something
}
});
但是数据库不显示任何新记录,控制台也不显示任何错误、异常或最后的日志语句
您将如何使用Spring和Cassandra在后台线程上保存记录
任何解释都将不胜感激
我已经在异步服务和事务服务以及其他一些服务中看到并尝试了以下内容:
当一个CompletableFuture异常完成时,没有stacktrace,因为该异常仍未处理。它一直存储到用户执行激活该异常的操作为止。例如,调用get将直接抛出该异常
当处理更复杂的事情时,异常会随将来的结果一起存储,因此双消费者会将结果和异常作为参数,但这取决于您检查是否存在异常并对其进行处理
由于可以链接未来,因此会遇到多个异常,因此最终会得到如下文档:
如果提供的操作本身遇到异常,则
返回的阶段异常完成,但出现此异常,除非
这个阶段也例外地完成了
如果你一读就明白了这一点,那你就很有天赋。展示一下你叫myBool.get的地方。@Kayaman你为什么要这个?这会影响我的记录不保存到后台线程上的数据库吗?因为你忽略了一个可能出现的异常。这是个好消息。@Kayaman!我一直在训练我的眼睛很长时间;
public boolean process() {
//This appears in the console
LOG.info("About to try and save the record on the background thread");
//After setting the repository in the thread class constructor
myRepository.save(arg1, arg2, arg3);
//This doesn't appear in the console
LOG.info("The record should be saved");
}