Grails如何向PromiseList

时间:2016-01-09 07:10:12

标签: grails groovy

我试图将大型集合上的一个任务分成几个线程,每个线程处理该集合的一部分。但是我无法将其传递给PromiseList。代码如下所示

def extractTask={myItems->
    //work flow logics here, create some domain entities
}
def missions=//a collection of lists, each will be used as the "myItems" in the closure
Collection results;
PromiseList promises;
//trying to create a Promise on each list in that collection
missions.collect{myTask->
    Promise p=task{extractTask(myTask)}
    if(p==null)
        println "Promise is null!";
        promises.add(p);
    }
    results=promises.get();
    promises.onError{Throwable t->
        println "Got error in parallel keyword extraction.";
        println t.message;
    }
}

代码抛出NullPointerException:

Cannot invoke method add() on null object. Stacktrace follows: java.lang.NullPointerException: Cannot invoke method add() on null object

这有点过头了。在调试模式下,我可以看到Promise p不为null。请大家详细说明:)非常感谢!

0 个答案:

没有答案