我已经从'org.codehaus.gpars:gpars:1.0.0'更新为'org.codehaus.gpars:gpars:1.1.0'。我的代码在1.0.0中可以正常工作,但是在1.1.0版中,我找不到jsr166y.ForkJoinPool。

如何获得正确的ForkJoinPool?

我使用的代码是:

import groovyx.gpars.GParsPool
import jsr166y.ForkJoinPool

class Test {
   def pool = new ForkJoinPool()

   def executeAsync(args, closure = null) {
    if(!closure) {
        closure = args
        args = null
    }

    GParsPool.withExistingPool(pool) {
        closure.callAsync(args)
    }
   }
}

我必须导入java.util.concurrent.ForkJoinPool以获取ForkJoinPool类。但是在运行时,出现以下错误:
| Error 2013-08-01 13:26:45,807 [http-nio-8080-exec-4] ERROR
errors.GrailsExceptionResolver  - ClassNotFoundException occurred when processing
request: [POST] /testpackage/test/saveAll - parameters:
jsr166y.ForkJoinPool. Stacktrace follows:
Message: jsr166y.ForkJoinPool
Line | Method
->>  175 | findClass                 in org.codehaus.groovy.tools.RootLoader
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    423 | loadClass                 in java.lang.ClassLoader
|    147 | loadClass . . . . . . . . in org.codehaus.groovy.tools.RootLoader
|    356 | loadClass                 in java.lang.ClassLoader
|   2451 | privateGetDeclaredMethods in java.lang.Class
|   1810 | getDeclaredMethods        in     ''
|     46 | getLocked . . . . . . . . in org.codehaus.groovy.util.LazyReference
|     33 | get                       in     ''
|    318 | saveAll . . . . . . . . . in testpackage.UploadImageController
|    195 | doFilter                  in
grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter . . . . . . . .  in grails.plugin.cache.web.filter.AbstractFilter
|   1145 | runWorker                 in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run                       in java.lang.Thread
| Compiling 1 source files.

最佳答案

将您的BuildConfog.groovy更新为:

compile 'org.codehaus.gpars:gpars:1.1.0'
compile 'org.codehaus.jsr166-mirror:jsr166y:1.7.0'

这应该为您工作。

关于multithreading - 找不到Gpars withExistingPool错误jsr166y.ForkJoinPool,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17993018/

10-11 09:20