serviceHub.startFlow from a cordaService class versus subFlow calling from Corda flow

huangapple go评论53阅读模式
英文:

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))
      }

huangapple
  • 本文由 发表于 2023年2月8日 20:27:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75385788.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定