我有一些工作需要为我的应用程序处理图像。它们占用大量堆内存。因此,我想限制图像处理任务的数量或以某种方式对它们进行排队。
我还使用GPars处理图像处理,但按照我的方法,有时会同时打开许多工作线程。
如何在 Grails 中使用 ThreadPoolExecutor 来正确完成此任务?
最佳答案
我认为你可以使用 GParsExecutorsPool 来做到这一点
GParsExecutorsPool.withPool() {
Closure longLastingCalculation = {calculate()}
Closure fastCalculation = longLastingCalculation.async() //create a new closure, which starts the original closure on a thread pool
Future result=fastCalculation() //returns almost immediately
//do stuff while calculation performs …
println result.get()
}
有关更多详细信息,请查看此链接: Use of ThreadPool - the Java Executors' based concurrent collection processor
关于java - ThreadPoolExecutor 处理 Grails 中的高内存任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18451605/