Java ThreadPoolExecutor在Grails中处理高内存任务?
我有一些为我的应用程序处理图像的工作。它们占用大量堆内存。因此,我想限制图像处理任务的数量,或者以某种方式将它们排队 我也用它来处理图像处理,但用我的方法,有时许多工作线程是同时打开的Java ThreadPoolExecutor在Grails中处理高内存任务?,java,spring,servlets,grails,grails-2.0,Java,Spring,Servlets,Grails,Grails 2.0,我有一些为我的应用程序处理图像的工作。它们占用大量堆内存。因此,我想限制图像处理任务的数量,或者以某种方式将它们排队 我也用它来处理图像处理,但用我的方法,有时许多工作线程是同时打开的 如何在Grails中使用ThreadPoolExecutor来完成这项工作?我认为可以通过使用GParExecutorSpool来完成这项工作 GParsExecutorsPool.withPool() { Closure longLastingCalculation = {calculate()
如何在Grails中使用ThreadPoolExecutor来完成这项工作?我认为可以通过使用GParExecutorSpool来完成这项工作
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()
}
有关更多详细信息,请查看此链接: