我使用GPars來執行後臺任務的並行進程。我使用以下服務來啓動一個新的後臺線程。限制Gpars中的線程數量?
保存堆內存如何限制後臺線程的數量?
如何定義處理我的後臺任務的n個線程的線程池?
import jsr166y.ForkJoinPool class TaskService { private pool = new ForkJoinPool() def executeAsync(args, closure = null) { if(!closure) { closure = args args = null } GParsPool.withExistingPool(pool) { closure.callAsync(args) } } }
我是否明白這一點?服務是Singelton,所以我的應用只有一個實例。 pool = new ForkJoinPool()只會實例化一次嗎? – confile
當我使用pool = new ForkJoinPool(4)並調用taskService時。 executeAsync(...)5次從我的應用程序。在這種情況下會發生什麼?這5個任務是從4個線程執行還是執行4個任務,最後一個任務將被阻止? – confile
默認情況下,Grails服務是Singelton:http://grails.org/doc/latest/guide/services.html – confile