Weird behavior with Constructor and Class. Application hangs `forever` on Constructor
<p><strong>UPDATE NOTE:</strong> After Debugging, I asked another question with the results: <a href="http://stackoverflow.com/questions/11738383/class-constructor-fails-throwing-exception-on-class-loading">Class Constructor fails throwing Exception on Class Loading</a></p>

<p>First, I could not think of a better name for my question, what I'm about to ask is just that: <strong>WEIRD BEHAVIOR</strong>. If you think of something more appropriate please edit.</p>

<p>Now, I'm going to try to simplify this as much as I can, sadly I can't give away the code which is giving me the problems.</p>

<p>I have a <strong>Class A</strong>, a <strong>Class B</strong> and a <strong>Class Z</strong>.</p>

<p><strong>Class A and B</strong> are very very similar, both have a constructor with the same params, and each have a method which invokes a SOAP web service, one to do <strong>Operation A</strong>, and the other to do <strong>Operation B</strong>.</p>

<p>Now,what's the problem? <code>Class Z</code> instantiates both <code>Class A</code> and <code>Class B</code> and then on <code>someMethod()</code> calls the object's method to do Operation A and B respectively.</p>

<p>For some reason the constructor of ClassB doesn't seem to be called, and no <code>System.out.println()</code> prints anything from the moment the Constructor is called, the program hangs <strong>forever</strong>, i mean it, it never throws and exception or continues to do anything. Look how on the first line of Class A and Class B I print a flag, it does not print for ClassB.</p>

<p><strong>WHAT I'VE TRIED</strong></p>

<ol>
<li>On <code>ClassZ</code> I changed the order for Class A and B -> <strong>RESULTS</strong>: It hangs on the same place and now not even Class A constructor and method gets called</li>
<li><p>On ClassB I commented everything, and started de-commenting each instruction one by one, starting with the Constructor and then with MethodB, here's where I got stuck and came here, because what I found makes no sense for me nor anybody at my workplace. <strong>RESULTS -></strong></p>

<p><strong>2.1</strong> If I comment everything on <code>methodB</code> but the return false in the end and leave the Constructor as is, it continues execution normally</p>

<p><strong>2.2</strong> If I de-comment everything on 2.1 plus just the part from <code>methodB</code> where it invokes the operationB from the WebService and checks it's result, it continues execution normally</p>

<p><strong>2.3</strong> If I de-comment a little bit more, when I start playing around with the database, it hangs.</p></li>
<li><p>I checked the number of Connections to the Database, it still has many available</p></li>
</ol>

<p><strong>What has me confused is, if it's something Database related, why does it hangs like that at the constructor?</strong> </p>

<p><strong>GENERAL FACTS</strong></p>

<ol>
<li>I'm using JDBC to connect to a MySQL Database</li>
<li>I have everything around try{}catch(Exception e){} and I'm printing everything on e, but it just doesn't print anything, no exception is thrown.</li>
</ol>

<p>Here's what they look like:</p>

<p><strong>CLASS A:</strong></p>

<pre><code>// ClassA.java

public ClassA{
    private UserInfo user;
    private WebServiceADelegate port;
    private Connection conn;

    public ClassA (UserInfo user, Connection conn) throws Exception {
        System.out.println("CLASS A CONSTRUCTOR");
        this.user = user;
        this.conn = conn;
        this.port = new WebServiceAService().getForwardingPort();
    }

    public boolean methodA(List&lt;String&gt; list){
        // Check some stuff on database using this.conn
        // Get the values to invoke SOAP service using this.conn
        status = port.operationA(values);
        if(status &gt; 0)
            return true;
        return false;
    }

}
</code></pre>

<p><strong>CLASS B:</strong></p>

<pre><code>// ClassB.java

public ClassB{
    private UserInfo user;
    private WebServiceBDelegate port;
    private Connection conn;

    public ClassB (UserInfo user, Connection conn) throws Exception {
        System.out.println("CLASS B CONSTRUCTOR");
        this.user = user;
        this.conn = conn;
        this.port = new WebServiceBService().getForwardingPort();
    }

    public boolean methodB(List&lt;String&gt; list){
        // Check some stuff on database using this.conn
        // Get the values to invoke SOAP service using this.conn
        status = port.operationB(values);
        if(status &gt; 0)
            return true;
        return false;
    }

}
</code></pre>

<p><strong>CLASS Z:</strong></p>

<pre><code>// ClassZ.java

public ClassZ{
    private Connection conn;
    // ...        
    // ...
    public boolean someMethod (){
        System.out.println("GONNA CALL CONSTRUCTOR ClassA");
        ClassA webservice = new ClassA(user, conn);
        System.out.println("GONNA CALL METHOD FROM ClassA");
        if (!webservice.methodA(list) ){
            return false;
        }

        System.out.println("GONNA CALL CONSTRUCTOR ClassB");
        ClassB webservice2 = new ClassB(user, conn);
        System.out.println("GONNA CALL METHOD FROM ClassB");
        if (!webservice2.methodB(list) ){
            return false;
        }
        return true;
    }
}
</code></pre>

<p>The last output when it hangs it's always: <code>"GONNA CALL CONSTRUCTOR ClassB"</code></p>

<p>Thanks!</p>

<p><strong>UPDATE:</strong></p>

<p>I debugged my app and got to fix it, however it's still really strange. Tomorrow I'll elaborate more to see if somebody can tell me what was going on.</p>

<p>Long story short: I was importing <code>javax.persistence.NoResultException</code> on ClassB, and on some point inside methodB i was doing <code>try{}catch(NoResultException nre){ //...}</code>… For some reason when the JVM was calling the ClassLoader before calling the Constructor it was throwing the aforementioned Exception and the behavior from that point was just weird and the execution ended.</p>

<p>There are threads involved, that's why I though it hang, it didn't hang, the Thread ended and I didn't notice.</p>

<p>An additional note: ClassB <strong>IS NOT</strong> using JPA, and the import as well as the catch for it were incorrectly there, some really old code that managed to survive. However I think it doesn't justify the error.</p>

<p>I asked another question, one with the findings of the Debugging. You might check it in <a href="http://stackoverflow.com/questions/11738383/class-constructor-fails-throwing-exception-on-class-loading">Class Constructor fails throwing Exception on Class Loading</a></p>
