Java deadlock
It can also become a static field on ClassName or a new TypeNames class, if that’s what you want the API to look like, but it can’t stay as is. Only OBJECT fits this candidate, so it may not be that harsh of a change. The solution here is not an easy one.It requires breaking existing API (not great) and making all ClassName constants into lazily-loaded fields locked behind public methods, so that TypeName’s initialization does not require loading ClassName. If you initialize ClassName in one thread while simultaneously initializing TypeName in another, the ClassName thread will try to acquire the TypeName class loading lock, and the TypeName thread will try to acquire the ClassName class loading lock, thus creating a deadlock. The issue is that TypeName has static constants that load its subclasses ( ClassName). This should really be fixed, as it means Javapoet can’t easily be used in a multi-threaded environment. The current hypothesis is that it is related to, where ClassName is a subclass of TypeName, but TypeName has a static variable of type ClassName here. We are seeing deadlocks when running several different instances of java poet in parallel threads "Task worker for ':' Thread 2" #147 prio=5 os_prio=0 tid=0x00007fcdb870a000 nid=0圆894 in Object.wait() Īt $Builder.(TypeSpec.java:403)Īt $Builder.(TypeSpec.java:394)Īt .interfaceBuilder(TypeSpec.java:121)














