<style>
/* Changing the layout to use less space for mobiles */
@media screen and (max-device-width: 480px), screen and (-webkit-min-device-pixel-ratio: 2) {
    #email-body { min-width: 30em !important; }
    #email-page { padding: 8px !important; }
    #email-banner { padding: 8px 8px 0 8px !important; }
    #email-avatar { margin: 1px 8px 8px 0 !important; padding: 0 !important; }
    #email-fields { padding: 0 8px 8px 8px !important; }
    #email-gutter { width: 0 !important; }
}
</style>
<div id="email-body">
<table id="email-wrap" align="center" border="0" cellpadding="0" cellspacing="0" style="background-color:#f0f0f0;color:#000000;width:100%;">
    <tr valign="top">
        <td id="email-page" style="padding:16px !important;">
            <table align="center" border="0" cellpadding="0" cellspacing="0" style="background-color:#ffffff;border:1px solid #bbbbbb;color:#000000;width:100%;">
                <tr valign="top">
                    <td bgcolor="#3b4d64" style="background-color:#3b4d64;color:#ffffff;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;line-height:1;"><img src="https://issues.jboss.org/s/en_US-x52yjt-1988229788/6109/58/_/jira-logo-scaled.png" alt="" style="vertical-align:top;" /></td>
                </tr><tr valign="top">
    <td id="email-banner" style="padding:32px 32px 0 32px;">
        
                
                    <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%" style="width:100%;">
    <tr valign="top">
        <td style="color:#505050;font-family:Arial,FreeSans,Helvetica,sans-serif;padding:0;">
                                        <img id="email-avatar" src="https://community.jboss.org/people/nuno.godinhomatos/avatar/16.png" alt="" height="48" width="48" border="0" align="left" style="padding:0;margin: 0 16px 16px 0;" />
                        <div id="email-action" style="padding: 0 0 8px 0;font-size:12px;line-height:18px;">
                                    <a class="user-hover" rel="nuno.godinhomatos" id="email_nuno.godinhomatos" href="https://issues.jboss.org/secure/ViewProfile.jspa?name=nuno.godinhomatos" style="color:#3b73af;">Nuno Godinho de Matos</a>
     created <img src="https://issues.jboss.org/images/icons/issuetypes/bug.png" height="16" width="16" border="0" align="absmiddle" alt="Bug"> <a style='color:#3b73af;text-decoration:none;' href='https://issues.jboss.org/browse/WELD-1619'>WELD-1619</a>
            </div>
                        <div id="email-summary" style="font-size:16px;line-height:20px;padding:2px 0 16px 0;">
                <a style='color:#3b73af;text-decoration:none;' href='https://issues.jboss.org/browse/WELD-1619'><strong>Java SE (weld-se) With surefire threaded perl class fails after the first thread call to weld.shutdown</strong></a>
            </div>
                    </td>
    </tr>
</table>
    </td>
</tr>
<tr valign="top">
    <td id="email-fields" style="padding:0 32px 32px 32px;">
        <table border="0" cellpadding="0" cellspacing="0" style="padding:0;text-align:left;width:100%;" width="100%">
            <tr valign="top">
                <td id="email-gutter" style="width:64px;white-space:nowrap;"></td>
                <td>
                    <table border="0" cellpadding="0" cellspacing="0" width="100%">
                        <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Issue Type:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
                <img src="https://issues.jboss.org/images/icons/issuetypes/bug.png" height="16" width="16" border="0" align="absmiddle" alt="Bug">        Bug
    </td>
</tr>                        <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Affects Versions:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
                    2.1.2.Final,                     1.2.0.Beta1            </td>
</tr>
                        <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Assignee:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
                            <a class="user-hover" rel="jharting" id="email_jharting" href="https://issues.jboss.org/secure/ViewProfile.jspa?name=jharting" style="color:#3b73af;">Jozef Hartinger</a>
        </td>
</tr>                                                <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Components:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
                    Interceptors and Decorators,                     Java SE Support            </td>
</tr>
                        <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Created:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
        13/Mar/14 9:53 AM
    </td>
</tr>                        <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Description:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
        <p style='margin-top:0;margin-bottom:10px;'>I am creating some UI Tests based on selenium. UI testing is overall a slow process with the opening of the browser and all the orchestration, so multi-threading the tests is a must.</p>

<p style='margin-top:0;margin-bottom:10px;'>Intially I was using Google Guice for IoC, but I have switched to weld. <br/>
The UI tests used to be successful in Guice using surefire &lt;threadCound&gt;&lt;/threadCoun&gt; configuration property.<br/>
When I switched to Weld, this stopped being the case.<br/>
The tests consistently break with several different exceptions at several different points of the life cycle of the test.</p>

<p style='margin-top:0;margin-bottom:10px;'>Summary of test policy:<br/>
Each test class contains a Weld and WeldContainer object that is unique to itself and not shared in any way. There are no race conditions on  these objects, since each test class contains a single test, and each test is given a single thread by the surefire plugin.</p>

<p style='margin-top:0;margin-bottom:10px;'>What seems to be happening here is that the <br/>
weld.shutdown();</p>

<p style='margin-top:0;margin-bottom:10px;'>call seems to have a cross cutting power across all the running threads.<br/>
That is, even though each test class has its own weld object that it uses to create a weld container.<br/>
As soon as the first test thread concludes the test and reaches the tearDown() moment, and invokes weld.shutdown(), from this point onward the ramaining tests seem to start dieing with arbitrary exceptions.</p>

<p style='margin-top:0;margin-bottom:10px;'>For example, I have head tests where the container.initilize() appears to be very successful, but after that trying to get a bean from the container will result in a:<br/>
WELD-001308 Unable to resolve any beans for Types: </p>

<p style='margin-top:0;margin-bottom:10px;'>Other tests that seem to have passe the @Test() point ad have reached teh tearDown() phase, these will failing trying to close the weld instance variable with arbtirary erros, such as:</p>

<p style='margin-top:0;margin-bottom:10px;'>java.lang.NullPointerException<br/>
        at org.jboss.weld.environment.se.ShutdownManager.shutdown(ShutdownManager.java:42)<br/>
        at org.jboss.weld.environment.se.ShutdownManager$Proxy$<em>$$_WeldClientProxy.shutdown(ShutdownManager$Proxy$</em>$$_WeldClientProxy.java)<br/>
        at org.jboss.weld.environment.se.Weld.shutdown(Weld.java:218)</p>


<p style='margin-top:0;margin-bottom:10px;'>Or such as:<br/>
java.lang.IllegalStateException: Singleton is not set. Is your Thread.currentThread().getContextClassLoader() set correctly?<br/>
        at org.jboss.weld.bootstrap.api.helpers.IsolatedStaticSingletonProvider$IsolatedStaticSingleton.get(IsolatedStaticSingletonProvider.java:52)<br/>
        at org.jboss.weld.Container.instance(Container.java:67)<br/>
        at org.jboss.weld.bean.AbstractBean.initialize(AbstractBean.java:134)<br/>
        at org.jboss.weld.bean.AbstractClassBean.initialize(AbstractClassBean.java:205)<br/>
        at org.jboss.weld.bean.ManagedBean.initialize(ManagedBean.java:327)<br/>
        at org.jboss.weld.bootstrap.AbstractBeanDeployer.deploy(AbstractBeanDeployer.java:116)<br/>
        at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:217)<br/>
        at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:365)<br/>
        at org.jboss.weld.bootstrap.api.helpers.ForwardingBootstrap.deployBeans(ForwardingBootstrap.java:70)<br/>
        at org.jboss.weld.environment.se.Weld.initialize(Weld.java:137)<br/>
        at WeldBugReportSurefireTest.setUp(WeldBugReportSurefireTest.java:65)</p>



<p style='margin-top:0;margin-bottom:10px;'>It is very hard to decide on an exception to report, so many take place an arbitrarly. </p>

<p style='margin-top:0;margin-bottom:10px;'>To make the tests pass I have have to use surefire configured for forking, witout re-use of forks. This solves my multi-threading issue.<br/>
But I am concerned with the erros I am getting, because I can envision scenarios where an application really needs to created different container objects that it shutsdown when appropriate without disturbing the other opened containers, as you can do with guice.</p>


<p style='margin-top:0;margin-bottom:10px;'>I have tried to compile a small project where this error can be reproduced.<br/>
I cannot use the real project for privacy reasons, so the exceptions that my sample project yields do not correspond exactly to the ones I get in my project... </p>

<p style='margin-top:0;margin-bottom:10px;'>In this project, tests can be triggered through the comand line with either:<br/>
mvn test<br/>
mvn -P parallel test<br/>
the mvn test runs one test at a time, the normal way, and should be successful.<br/>
the mvn -P parallel test <br/>
should break most of the time with arbitrary exceptions on arbitrary test classes</p>

<p style='margin-top:0;margin-bottom:10px;'>And if the managed bean DummyManagedBean.java has a flag property that can be used to get the tests to pass when in parallel.<br/>
what this flag will do is make the thread postpone the test for long enough, for all other threads to complete their business logic, thus avoiding a weld shutdown to occur before the tests complete.</p>

    </td>
</tr>
                                                <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Environment:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
        windows 7 mvn 2
    </td>
</tr>
                                                <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Project:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
        <a style="color:#3b73af;" href="https://issues.jboss.org/browse/WELD">Weld</a>
    </td>
</tr>                                                <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Priority:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
                        <img src="https://issues.jboss.org/images/icons/priorities/major.png" height="16" width="16" border="0" align="absmiddle" alt="Major">                Major
    </td>
</tr>
                        <tr valign="top">
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:#505050;">Reporter:</strong>
    </td>
    <td style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 10px 0;width:100%;">
                                        <a class="user-hover" rel="nuno.godinhomatos" id="email_nuno.godinhomatos" href="https://issues.jboss.org/secure/ViewProfile.jspa?name=nuno.godinhomatos" style="color:#3b73af;">Nuno Godinho de Matos</a>
                </td>
</tr>                                                    
    
    
                        </table>
                </td>
            </tr>
        </table>
    </td>
</tr>













            </table>
        </td><!-- End #email-page -->
    </tr>
    <tr valign="top">
        <td style="color:#505050;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:10px;line-height:14px;padding: 0 16px 16px 16px;text-align:center;">
            This message is automatically generated by JIRA.<br />
            If you think it was sent incorrectly, please contact your JIRA administrators<br />
            For more information on JIRA, see: <a style='color:#3b73af;' href='http://www.atlassian.com/software/jira'>http://www.atlassian.com/software/jira</a>
        </td>
    </tr>
</table><!-- End #email-wrap -->
</div><!-- End #email-body -->