Concurrency Issue Loading Ops and OperatorImpl #1237

franciscospaeth opened this Issue Mar 5, 2015 · 2 comments


None yet

3 participants


Whenever com.mysema.query.types.OperatorImpl and com.mysema.query.types.Ops are loaded simultaneously loaded a deadlock is reached.

The following code could be used to reproduce the issue:

import org.junit.Test;

import com.mysema.query.jpa.impl.JPAQuery;

public class CycleClassInitDependencyTest {

    @Test(timeout = 2000)
    public void test() throws InterruptedException {

        // If class is loaded before hand it will work for example:
        // System.out.println(Ops.DateTimeOps.DATE);

        // each thread wants
        Thread t1 = new Thread(new LoadClassRunnable("com.mysema.query.types.OperatorImpl"));
        Thread t2 = new Thread(new LoadClassRunnable("com.mysema.query.types.Ops"));

        // trying to create anything depending on Ops class for instance:
        // JPAQuery -> JPQLTemplates -> Ops
        new JPAQuery();


    public class LoadClassRunnable implements Runnable {

        private String classToLoad;

        public LoadClassRunnable(String classToLoad) {
            this.classToLoad = classToLoad;

        public void run() {
            try {
            } catch (ClassNotFoundException e) {



A jstack relevant part of the execution of code exposed above is:

"OpslLoading        " prio=10 tid=0x00007f47a4003000 nid=0x2dd3 in Object.wait() [0x00007f47b7cfb000]
   java.lang.Thread.State: RUNNABLE
    at com.mysema.query.types.Ops.<clinit>(
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(
    at CycleClassInitDependencyTest$

"OperatorImplLoading" prio=10 tid=0x00007f47a4001800 nid=0x2dd2 in Object.wait() [0x00007f47b7dfb000]
   java.lang.Thread.State: RUNNABLE
    at sun.misc.Unsafe.ensureClassInitialized(Native Method)
    at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(
    at sun.reflect.ReflectionFactory.newFieldAccessor(
    at java.lang.reflect.Field.acquireFieldAccessor(
    at java.lang.reflect.Field.getFieldAccessor(
    at java.lang.reflect.Field.get(
    at com.mysema.query.types.OperatorImpl.<clinit>(
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(
    at CycleClassInitDependencyTest$

"Thread-0" prio=10 tid=0x00007f47ec205000 nid=0x2dd1 in Object.wait() [0x00007f47b7efc000]
   java.lang.Thread.State: RUNNABLE
    at com.mysema.query.types.Templates.<init>(
    at com.mysema.query.types.Templates.<init>(
    at com.mysema.query.types.Templates.<clinit>(
    at com.mysema.query.jpa.impl.JPAQuery.<init>(
    at CycleClassInitDependencyTest.test(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(
    at org.junit.internal.runners.statements.FailOnTimeout$

I have successfully reproduced this case, I will push your test case this afternoon.

@timowest I already tried some synchronization, but if one thread holds the lock for Ops, and the other for OperatorImpl. we have a problem (since they are dependent on each other).

timowest commented Mar 5, 2015

This could be solved by getting rid of the OPS cache in OperationImpl and reading the OperatorImpl in deserialization via the, since it is always FQCN#staticField.

Querydsl 4.0.0 won't have that issue since the Operator instances are enums.

@timowest timowest changed the title from Concurrency Issue Loading Opts and OperatorImpl to Concurrency Issue Loading Ops and OperatorImpl Mar 5, 2015
@timowest timowest added this to the 3.6.3 milestone Mar 6, 2015
@timowest timowest closed this Mar 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment