groovy

Concurrency issue when loading dependencies in the GroovyScriptEngine

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.0
  • Fix Version/s: 1.1-beta-2
  • Component/s: groovy-jdk
  • Labels:
    None
  • Environment:
    Linux/Windows
  • Testcase included:
    yes
  • Number of attachments :
    2

Description

When running a script for the first time using the GroovyScriptEngine, if two or more concurrent threads try to run it, it is possible that a concurrency issue happens when accessing updateCacheEntry at

groovy.util.GroovyScriptEngine.updateCacheEntry(GroovyScriptEngine.java:285)

I think this is due that the private Map "dependencies"
at

groovy.util.GroovyScriptEngine$ScriptCacheEntry.dependencies (GroovyScriptEngine.java:101)

is not synchronized. It could be solved by:

private Map dependencies= Collections.synchronizedMap(new HashMap());

I have attached my test case (to be run by executing the main method) and a sample groovy script.

  1. Test2.groovy
    01/Jun/07 10:23 AM
    0.5 kB
    David Costa Faidella
  2. TestFilesOpen.java
    01/Jun/07 10:23 AM
    2 kB
    David Costa Faidella

Activity

Hide
blackdrag blackdrag added a comment -

the dependencies map is now ThreadLocal, which solves your issue too

Show
blackdrag blackdrag added a comment - the dependencies map is now ThreadLocal, which solves your issue too

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: