У меня есть цикл, как показано в примере ниже, который работает. Я пытаюсь сделать его параллельным, но он дает ошибку. Как сделать его параллельным (или где проблема)?Попытка сделать петлю параллельной с ошибками GPars
Message: No signature of method: org.hibernate.collection.PersistentSet.eachParallel() is applicable for argument types: (com.example.ExampleController$_getOrgsWithSpec..
// Example domain class
Organization {
OrgProfile orgProfile
IndProfile indProfile
}
//same for IndProfile
OrgProfile {
static mapping = {
specs lazy:false
cache true
}
static hasMany = [
specs: Specs
]
}
// --------------------------------
//Controller methods
// Normal code (works)
def getOrgsWithSpec = { orgs ->
def s = []
orgs.each { o ->
if (o.type == 1) { //just an example
o.orgProfile?.specs?.findAll { m ->
if (m.id == specId) {
s.push(o)
}
}
} else if (o.type == 2) {
o.indProfile?.specs?.findAll { m ->
if (m.id == specId) {
s.push(o)
}
}
}
}
return s
}
// With GPars (not working)
def getOrgsWithSpec = { orgs ->
def s = []
GParsPool.withPool {
orgs.eachParallel { o ->
if (o.type == 1) {
o.orgProfile?.specs?.findAllParallel { m ->
if (m.id == specId) {
s.push(o)
}
}
} else if (o.type == 2) {
o.indProfile?.specs?.findAllParallel { m ->
if (m.id == specId) {
s.push(o)
}
}
}
}
}
return s
}
Да, я использую 'withPool'. См. Вторую функцию в контроллерах в приведенном выше примере. Аккумулятор '' 'не находится в пуле. Я попытался с 'collectParallel {}', и я думаю, что я получил mysql-соединение с закрытой ошибкой. (В настоящее время отсутствует код). – boring
Я беспокоюсь о том, что вызовы s.push() не синхронизируются каким-либо образом и все же вызывается из нескольких потоков. –
Я не могу поверить в то, что каждый из них Paral() не присутствует в организациях, а вы находитесь в блоке withPool. –