0

我有一些为我的应用程序处理图像的工作。它们占用大量堆内存。因此,我想限制图像处理任务的数量或以某种方式将它们排队。

我也使用GPars来处理图像,但我的方法有时会同时打开许多工作线程。

如何在 Grails 中使用 ThreadPoolExecutor 来完成这项工作?

4

1 回答 1

1

我认为你可以通过使用 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()
}

有关更多详细信息,请查看此链接: 使用 ThreadPool - Java Executors' based concurrent collection processor

于 2013-11-20T16:19:07.360 回答