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 "1 Thread[pool-1-thread-1,5,main]" nivel 1 ... <br><br>If i debug the source, i get that the thread is in following mode:<br><br>"pool-1-thread-1" 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 <0x1590c730> (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 & 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<String, String> environment = new Hashtable<String, String>();<br>
environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");<br> environment.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");<br> environment.put(Context.PROVIDER_URL, "jnp://localhost:1099");<br>
<br> InitialContext ctx = new InitialContext(environment);<br> Echo echo = (Echo) ctx.lookup("TestEAR/EchoBean/remote");<br> System.out.println("-------- Synchronous call");<br> String ret = echo.echo("1.- normal call");<br>
System.out.println(ret);<br><br> Echo asynchEcho = AsyncUtils.mixinAsync(echo);<br> <br> System.out.println("-------- Asynchronous call");<br> ret = asynchEcho.echo("2.- asynchronous call test");<br>
// deberia devolver null en ret<br> System.out.println("Direct return of async invocation is: " + ret);<br><br> System.out.println("-------- Synchronous call");<br> ret = echo.echo("3.- normal call 2");<br>
System.out.println(ret);<br><br> System.out.println("-------- Result of Asynchronous call");<br> Future<?> future = AsyncUtils.getFutureResult(asynchEcho);<br><br> System.out.println("Waiting for asynbch invocation to complete");<br>
ret = (String) future.get(500, TimeUnit.MILLISECONDS);<br> System.out.println(future.isDone());<br> System.out.println("->" + ret + " " + new Date());<br><br> // ThreadUtilities.getThread("pool-1-thread-1").interrupt();<br>
<br> System.out.println("FIN");<br> // new Thread().start();<br><br> //listThreads();<br> /*<br> System.out.println("----------------");<br> listThreads(); <br>
System.out.println(""+ new Date());<br> Thread.currentThread().sleep(60*1000);<br> System.out.println("----------------");<br> System.out.println(""+ 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'.<br>
public static void visit(ThreadGroup group, int level) {<br> // Get threads in `group'<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'<br> for (int i = 0; i < numThreads; i++) {<br> // Get thread<br> Thread thread = threads[i];<br> System.out.println(level + " " + thread);<br>
}<br> // Get thread subgroups of `group'<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 < numGroups; i++) {<br> visit(groups[i], level + 1);<br> }<br> }<br><br>}<br><br>/* ------------------------------ cut & 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>->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>