Hello, <br><br>I am testing async invocation using the examples in jboss 6.0 <br><br>I got a strange execution ... when the client finish, it hold for a seconds (around 50-60 seconds) before real end ...<br><br>If i put a System.exit , the execution is ok ...  i found that the AsyncUtils.mixinAsync and Future are in the trouble ...<br>
<br>When i list all threads remaining , i show a  &quot;1 Thread[pool-1-thread-1,5,main]&quot;  nivel 1 ... <br><br>If  i debug the source, i get that the thread is in following mode:<br><br>&quot;pool-1-thread-1&quot; prio=6 tid=0x04260000 nid=0xf80 waiting on condition [0x0667f000]<br>
   java.lang.Thread.State: WAITING (parking)<br>    at sun.misc.Unsafe.park(Native Method)<br>    - parking to wait for  &lt;0x1590c730&gt; (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)<br>    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)<br>
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1925)<br>    at java.util.concurrent.PriorityBlockingQueue.take(PriorityBlockingQueue.java:220)<br>    at org.jboss.resource.adapter.mail.inflow.NewMsgsWorker.run(NewMsgsWorker.java:78)<br>
    at org.jboss.resource.work.WorkWrapper.run(WorkWrapper.java:172)<br>    at org.jboss.threads.SimpleDirectExecutor.execute(SimpleDirectExecutor.java:33)<br>    at org.jboss.threads.QueueExecutor.runTask(QueueExecutor.java:780)<br>
    at org.jboss.threads.QueueExecutor.access$100(QueueExecutor.java:45)<br>    at org.jboss.threads.QueueExecutor$Worker.run(QueueExecutor.java:800)<br>    at java.lang.Thread.run(Thread.java:619)<br>    at org.jboss.threads.JBossThread.run(JBossThread.java:122)<br>
<br><br>and the main thread is blocked to end until this thread stop .... wasted 50 seconds ...<br><br>how can i do to fix it <br><br>thank you<br><br>/* ------------------------------ cut &amp; paste ------------------------------------------------------------ */<br>
<br><br>package paq;<br><br>import java.util.Date;<br>import java.util.Hashtable;<br>import java.util.concurrent.Future;<br>import java.util.concurrent.TimeUnit;<br><br>import javax.naming.Context;<br>import javax.naming.InitialContext;<br>
<br>import org.jboss.ejb3.common.proxy.plugins.async.AsyncUtils;<br><br>public class Client {<br>    public static void main(String[] args) throws Exception {<br>        Hashtable&lt;String, String&gt; environment = new Hashtable&lt;String, String&gt;();<br>
        environment.put(Context.INITIAL_CONTEXT_FACTORY,  &quot;org.jnp.interfaces.NamingContextFactory&quot;);<br>        environment.put(Context.URL_PKG_PREFIXES,  &quot;org.jboss.naming:org.jnp.interfaces&quot;);<br>        environment.put(Context.PROVIDER_URL, &quot;jnp://localhost:1099&quot;);<br>
<br>        InitialContext ctx = new InitialContext(environment);<br>        Echo echo = (Echo) ctx.lookup(&quot;TestEAR/EchoBean/remote&quot;);<br>        System.out.println(&quot;-------- Synchronous call&quot;);<br>        String ret = echo.echo(&quot;1.- normal call&quot;);<br>
        System.out.println(ret);<br><br>        Echo asynchEcho = AsyncUtils.mixinAsync(echo);<br>        <br>        System.out.println(&quot;-------- Asynchronous call&quot;);<br>        ret = asynchEcho.echo(&quot;2.- asynchronous call test&quot;);<br>
        // deberia devolver null en ret<br>        System.out.println(&quot;Direct return of async invocation is: &quot; + ret);<br><br>        System.out.println(&quot;-------- Synchronous call&quot;);<br>        ret = echo.echo(&quot;3.- normal call 2&quot;);<br>
        System.out.println(ret);<br><br>        System.out.println(&quot;-------- Result of Asynchronous call&quot;);<br>        Future&lt;?&gt; future = AsyncUtils.getFutureResult(asynchEcho);<br><br>        System.out.println(&quot;Waiting for asynbch invocation to complete&quot;);<br>
        ret = (String) future.get(500, TimeUnit.MILLISECONDS);<br>        System.out.println(future.isDone());<br>        System.out.println(&quot;-&gt;&quot; + ret + &quot; &quot; + new Date());<br><br>        // ThreadUtilities.getThread(&quot;pool-1-thread-1&quot;).interrupt();<br>
<br>        System.out.println(&quot;FIN&quot;);<br>        // new Thread().start();<br><br>        //listThreads();<br>        /*<br>        System.out.println(&quot;----------------&quot;);<br>        listThreads();            <br>
        System.out.println(&quot;&quot;+ new Date());<br>        Thread.currentThread().sleep(60*1000);<br>        System.out.println(&quot;----------------&quot;);<br>        System.out.println(&quot;&quot;+ new Date());<br>
        */<br>        listThreads();<br>        System.exit(0);<br>    }<br><br>    public static void listThreads() {<br>        // Find the root thread group<br>        ThreadGroup root = Thread.currentThread().getThreadGroup().getParent();<br>
        while (root.getParent() != null) {<br>            root = root.getParent();<br>        }<br>        // Visit each thread group<br>        visit(root, 0);<br>    }<br><br>    // This method recursively visits all thread groups under `group&#39;.<br>
    public static void visit(ThreadGroup group, int level) {<br>        // Get threads in `group&#39;<br>        int numThreads = group.activeCount();<br>        Thread[] threads = new Thread[numThreads * 2];<br>        numThreads = group.enumerate(threads, false);<br>
<br>        // Enumerate each thread in `group&#39;<br>        for (int i = 0; i &lt; numThreads; i++) {<br>            // Get thread<br>            Thread thread = threads[i];<br>            System.out.println(level + &quot; &quot; + thread);<br>
        }<br>        // Get thread subgroups of `group&#39;<br>        int numGroups = group.activeGroupCount();<br>        ThreadGroup[] groups = new ThreadGroup[numGroups * 2];<br>        numGroups = group.enumerate(groups, false);<br>
        // Recursively visit each subgroup<br>        for (int i = 0; i &lt; numGroups; i++) {<br>            visit(groups[i], level + 1);<br>        }<br>    }<br><br>}<br><br>/* ------------------------------ cut &amp; paste 
------------------------------------------------------------ */<br><br>/* *******************  CONSOLE OUTPUT *************************** */<br><br>-------- Synchronous call<br>1.- normal call<br>-------- Asynchronous call<br>
Direct return of async invocation is: null<br>-------- Synchronous call<br>3.- normal call 2<br>-------- Result of Asynchronous call<br>Waiting for asynbch invocation to complete<br>true<br>-&gt;2.- asynchronous call test Thu Jun 24 16:55:30 GMT+01:00 2010<br>
FIN<br>0 Thread[Reference Handler,10,system]<br>0 Thread[Finalizer,8,system]<br>0 Thread[Signal Dispatcher,9,system]<br>0 Thread[Attach Listener,5,system]<br>0 Thread[RMI RenewClean-[<a href="http://127.0.0.1:1098">127.0.0.1:1098</a>],5,system]<br>
0 Thread[GC Daemon,2,system]<br>0 Thread[RMI Scheduler(0),5,system]<br>1 Thread[main,5,main]<br>1 Thread[pool-1-thread-1,5,main]<br><br><br><br>