英文:
serviceHub.startFlow from a cordaService class versus subFlow calling from Corda flow
问题
在从另一个 Corda 流中将一个流称为 subflow 与从 Corda 服务类中调用相同的流,即 serviceHub.startFlow,是否存在差异?
在线程利用或暂停等方面是否有差异?
我遇到了这样的情况,从 CordaService 函数调用一个流时,出现了错误,如下所示:
java.lang.IllegalArgumentException: Transaction context is missing. This might happen if a suspendable method is not annotated with @Suspendable annotation.
而从另一个流中使用子流调用相同的流却运行正常。
英文:
Is there a difference in calling one flow as subflow from another corda flow versus calling the same flow from a cordaservice class as serviceHub.startFlow?
In terms of thread utilization or suspending etc?
I encountered a scenario where calling a flow from CordaService function got me error like
java.lang.IllegalArgumentException: Transaction context is missing. This might happen if a suspendable method is not annotated with @Suspendable annotation.
whereas calling the same flows from another flow using subflows worked fine.
答案1
得分: 0
当我们从服务调用流程时,最佳实践是从其自己的线程中调用,以避免事务更新的死锁。
在@CordaService类内部
private companion object {
val executor: Executor = Executors.newCachedThreadPool()
}
-------------------------------------------------------------------
executor.execute {
serviceHub.startFlow(RegisterCarFlow(update))
}
英文:
When we call a flow from service it good practice to call it from its own Thread to avoid Dead locks of transaction update.
Inside @CordaService class
private companion object {
val executor: Executor = Executors.newCachedThreadPool()
}
-------------------------------------------------------------------
executor.execute {
serviceHub.startFlow(RegisterCarFlow(update))
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论