我有一个执行多个 native sql 语句的服务。是否可以异步运行这些 sql 语句?我的查询看起来像这样,有多个查询:
def sessionFactory
sessionFactory = ctx.sessionFactory // this only necessary if your are working with the Grails console/shell
def session = sessionFactory.currentSession
def query = session.createSQLQuery("select f.* from fee f where f.id = :filter)) order by f.name");
最佳答案
您可以使用新的 grails Promises API
import static grails.async.Promises.*
List queriesToExecute = []
someList.each {
//create task to execute query
def t = task {
//create and execute query here
}
queriesToExecute << t
}
def result = waitAll(queriesToExecute) //if you want to wait till queries are executed
//or if you dont want to wait, use this - onComplete(queriesToExecute) { List results -> }
关于Grails 异步执行多个原生 sql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29769953/