gpt4 book ai didi

grails - Grails 中的异步编程

转载 作者:行者123 更新时间:2023-12-04 21:16:08 32 4
gpt4 key购买 nike

我在 Grails 应用程序中使用 Servlet 3.0 异步渲染。我收到以下错误。

| Error 2014-04-29 11:10:24,125 [Actor Thread 28] ERROR gpars.LoggingPoolFactory  - Async execution error: null
Message: null
Line | Method
->> 61 | doCall in org.grails.async.factory.gpars.GparsPromise$_onComplete_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 62 | run in groovyx.gpars.dataflow.DataCallback$1
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread

请帮我解决这个问题。

这是代码
    //Promise 1
Promise p1 = task {
println id+" p1 Task is Runing"
sleep(4000)
println id+" p1 Thread Woke Up"
return "p1Completed"
}

//Promise 2
Promise p2 = task {
println id+" p2 Task is Runing"
sleep(4000)
println id+" p2 Thread Woke Up"
return "p2Completed"
}
p1.onComplete { result ->
println id+" Promise p1 Completed returned "+result
}
p1.onError { Throwable err ->
println id+" p1 An error occured ${err.message}"
}
p2.onComplete { result ->
println id+" Promise p2 Completed returned "+result
}
p2.onError { Throwable err ->
println id+" p2 An error occured ${err.message}"
}

最佳答案

您需要在代码底部添加以下行:

p1.get()
p2.get()

这将阻止请求,直到两个 promise 都完成。如果要运行异步任务并结束请求而不同步等待响应,则需要使用 java executor 框架。检查这个问题: Error on async job

关于grails - Grails 中的异步编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23356538/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com