我有一个执行多个原生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");发布于 2015-04-21 20:44:10
您可以使用新的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 -> }https://stackoverflow.com/questions/29769953
复制相似问题