从另一个 corda 流调用一个流作为 subflow 与从 cordaservice 类调用相同流作为 serviceHub.startFlow 有区别吗?
在线程利用率或挂起等方面?
我遇到了一种情况,从 CordaService 函数调用流程时出现错误,例如
java.lang.IllegalArgumentException: Transaction context is missing. This might happen if a suspendable method is not annotated with @Suspendable annotation.
而使用子流从另一个流调用相同的流效果很好。
当我们从服务调用流程时,最好从其自己的线程调用它,以避免事务更新死锁。
@CordaService 类内部
private companion object {
val executor: Executor = Executors.newCachedThreadPool()
}
-------------------------------------------------------------------
executor.execute {
serviceHub.startFlow(RegisterCarFlow(update))
}
与使用自定义线程池相关的一个问题是,从服务内的子流或启动服务的流中获取结果很复杂。如果我们使用 Future 或 CompletableFuture,那么它就会违背同时运行这些子流的目的。 仅当发起者或服务不需要子流结果时,我们才能更轻松地使用此方法。