| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (

This example Groovy source code file ( is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

binding, binding, groovyscriptengine, groovyscriptengine, interruptedexception, io, ioexception, path, runner, runner, runtimeexception, string, string, testcase, throwable

The Groovy source code

package groovy.lang.gcldeadlock;

import groovy.lang.Binding;
import groovy.util.GroovyScriptEngine;
import junit.framework.TestCase;


 * Check that GroovyClassLoader (through GroovyScriptEngine) can compile scripts concurrently.
 * Test for GROOVY-4002
 * @author Guillaume Laforge
public class GroovyClassLoaderDeadlockTest extends TestCase {
    private static final String PATH = "./src/test/groovy/lang/gcldeadlock/";

    private static class Runner extends Thread {
        private GroovyScriptEngine gse;
        private String script;
        private int count;
        private String result = "";

        public Runner(GroovyScriptEngine gse, String script, int count) {
            this.gse = gse;
            this.script = script;
            this.count = count;

        public void run() {
            try {
                Binding b = new Binding();
                b.setVariable("number", count);
                result = (String), b);
            } catch (Throwable t) {
                throw new RuntimeException("problem running script", t);

        public String getResult() {
            return result;

    public void testNoDeadlockWhenTwoThreadsCompileScripts() throws IOException, InterruptedException {
        String[] roots = new String[] { PATH };
        GroovyScriptEngine gse = new GroovyScriptEngine(roots);
        Runner[] runners = new Runner[] {
                new Runner(gse, "script0.groovy", 0),
                new Runner(gse, "script1.groovy", 1)
        for (Runner runner : runners) {
        for (Runner runner : runners) {
        assertEquals("0+0=0", runners[0].getResult());
        assertEquals("1+1=2", runners[1].getResult());

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.