Groovy
  1. Groovy
  2. GROOVY-4286

GroovyScriptEngine doesn't recompile updateted script

    Details

      Description

      If you run the following java code and alter the executed script while running, it is unpredictable when GroovyScriptEngine recompiles the script. Sometimes it works, sometimes not.

      GroovyScriptEngineTest.java
      public class GroovyScriptEngineTest {
      
      	public static void main(String[] args) throws Exception {
      
      		GroovyScriptEngine groovyScriptEngine = new GroovyScriptEngine("/home/peddn/groovy");
      		
      		groovyScriptEngine.getConfig().setMinimumRecompilationInterval(0);
      		
      		while (true) {
      
      			Class<?> groovyClass = groovyScriptEngine.loadScriptByName("TestPrint.groovy");
      
      			GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
      
      			Object[] groovyArgs = {};
      
      			groovyObject.invokeMethod("testPrint", groovyArgs);
      
                              //check for recompile every half second
      			Thread.sleep(500L);
      
      		}
      
      	}
      
      }
      
      class TestPrint {
      
      	public void testPrint() {
      		
      		System.out.println("hello World");
      		
      	}
      	
      }
      

      here some suggestions from a discussion at the mailing list:

      I fact I think its kind of bug in GroovyScriptEngine here is code
      snippet:

          protected boolean isSourceNewer(ScriptCacheEntry entry) throws 
      ResourceException  { 
              if (entry == null) return true; 
              long time = System.currentTimeMillis(); 
      
              ScriptCacheEntry newEntry = new 
      ScriptCacheEntry(depEntry.scriptClass, time, depEntry.dependencies); 
              scriptCache.put(scriptName, newEntry); 
          } 
      

      I think more right solution is using aomthing like this:

          protected boolean isSourceNewer(ScriptCacheEntry entry) throws 
      ResourceException  { 
              if (entry == null) return true; 
              long time = long time = <get entry file lastModified 
      timestamp> 
      
              ScriptCacheEntry newEntry = new 
      ScriptCacheEntry(depEntry.scriptClass, time, depEntry.dependencies); 
              scriptCache.put(scriptName, newEntry); 
          }
      

        Activity

        Peter Schmid created issue -
        Guillaume Delcroix made changes -
        Field Original Value New Value
        Component/s GroovyScriptEngine [ 14484 ]
        Guillaume Delcroix made changes -
        Assignee Guillaume Laforge [ guillaume ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.7.4 [ 16563 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Fix Version/s 1.8-beta-1 [ 16013 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12733229 ] Default workflow, editable Closed status [ 12745063 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12967457 ] Default workflow, editable Closed status [ 12975156 ]

          People

          • Assignee:
            Guillaume Delcroix
            Reporter:
            Peter Schmid
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development