【问题标题】:ThreadPoolExecutor to handle high Memory Tasks in Grails?ThreadPoolExecutor 在 Grails 中处理高内存任务?
【发布时间】:2013-08-29 09:13:13
【问题描述】:

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

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

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

【问题讨论】:

    标签: java spring servlets grails grails-2.0


    【解决方案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()
    }
    

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

    【讨论】:

      猜你喜欢
      • 2018-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-23
      • 2011-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多