[jboss-user] AsyncUtils.mixinAsync future lock for a minute

Javier Sanz jsanza at gmail.com
Thu Jun 24 11:10:18 EDT 2010


Hello,

I am testing async invocation using the examples in jboss 6.0

I got a strange execution ... when the client finish, it hold for a seconds
(around 50-60 seconds) before real end ...

If i put a System.exit , the execution is ok ...  i found that the
AsyncUtils.mixinAsync and Future are in the trouble ...

When i list all threads remaining , i show a  "1
Thread[pool-1-thread-1,5,main]"  nivel 1 ...

If  i debug the source, i get that the thread is in following mode:

"pool-1-thread-1" prio=6 tid=0x04260000 nid=0xf80 waiting on condition
[0x0667f000]
   java.lang.Thread.State: WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x1590c730> (a
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
    at
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1925)
    at
java.util.concurrent.PriorityBlockingQueue.take(PriorityBlockingQueue.java:220)
    at
org.jboss.resource.adapter.mail.inflow.NewMsgsWorker.run(NewMsgsWorker.java:78)
    at org.jboss.resource.work.WorkWrapper.run(WorkWrapper.java:172)
    at
org.jboss.threads.SimpleDirectExecutor.execute(SimpleDirectExecutor.java:33)
    at org.jboss.threads.QueueExecutor.runTask(QueueExecutor.java:780)
    at org.jboss.threads.QueueExecutor.access$100(QueueExecutor.java:45)
    at org.jboss.threads.QueueExecutor$Worker.run(QueueExecutor.java:800)
    at java.lang.Thread.run(Thread.java:619)
    at org.jboss.threads.JBossThread.run(JBossThread.java:122)


and the main thread is blocked to end until this thread stop .... wasted 50
seconds ...

how can i do to fix it

thank you

/* ------------------------------ cut & paste
------------------------------------------------------------ */


package paq;

import java.util.Date;
import java.util.Hashtable;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import javax.naming.Context;
import javax.naming.InitialContext;

import org.jboss.ejb3.common.proxy.plugins.async.AsyncUtils;

public class Client {
    public static void main(String[] args) throws Exception {
        Hashtable<String, String> environment = new Hashtable<String,
String>();
        environment.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
        environment.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
        environment.put(Context.PROVIDER_URL, "jnp://localhost:1099");

        InitialContext ctx = new InitialContext(environment);
        Echo echo = (Echo) ctx.lookup("TestEAR/EchoBean/remote");
        System.out.println("-------- Synchronous call");
        String ret = echo.echo("1.- normal call");
        System.out.println(ret);

        Echo asynchEcho = AsyncUtils.mixinAsync(echo);

        System.out.println("-------- Asynchronous call");
        ret = asynchEcho.echo("2.- asynchronous call test");
        // deberia devolver null en ret
        System.out.println("Direct return of async invocation is: " + ret);

        System.out.println("-------- Synchronous call");
        ret = echo.echo("3.- normal call 2");
        System.out.println(ret);

        System.out.println("-------- Result of Asynchronous call");
        Future<?> future = AsyncUtils.getFutureResult(asynchEcho);

        System.out.println("Waiting for asynbch invocation to complete");
        ret = (String) future.get(500, TimeUnit.MILLISECONDS);
        System.out.println(future.isDone());
        System.out.println("->" + ret + " " + new Date());

        // ThreadUtilities.getThread("pool-1-thread-1").interrupt();

        System.out.println("FIN");
        // new Thread().start();

        //listThreads();
        /*
        System.out.println("----------------");
        listThreads();
        System.out.println(""+ new Date());
        Thread.currentThread().sleep(60*1000);
        System.out.println("----------------");
        System.out.println(""+ new Date());
        */
        listThreads();
        System.exit(0);
    }

    public static void listThreads() {
        // Find the root thread group
        ThreadGroup root =
Thread.currentThread().getThreadGroup().getParent();
        while (root.getParent() != null) {
            root = root.getParent();
        }
        // Visit each thread group
        visit(root, 0);
    }

    // This method recursively visits all thread groups under `group'.
    public static void visit(ThreadGroup group, int level) {
        // Get threads in `group'
        int numThreads = group.activeCount();
        Thread[] threads = new Thread[numThreads * 2];
        numThreads = group.enumerate(threads, false);

        // Enumerate each thread in `group'
        for (int i = 0; i < numThreads; i++) {
            // Get thread
            Thread thread = threads[i];
            System.out.println(level + " " + thread);
        }
        // Get thread subgroups of `group'
        int numGroups = group.activeGroupCount();
        ThreadGroup[] groups = new ThreadGroup[numGroups * 2];
        numGroups = group.enumerate(groups, false);
        // Recursively visit each subgroup
        for (int i = 0; i < numGroups; i++) {
            visit(groups[i], level + 1);
        }
    }

}

/* ------------------------------ cut & paste
------------------------------------------------------------ */

/* *******************  CONSOLE OUTPUT *************************** */

-------- Synchronous call
1.- normal call
-------- Asynchronous call
Direct return of async invocation is: null
-------- Synchronous call
3.- normal call 2
-------- Result of Asynchronous call
Waiting for asynbch invocation to complete
true
->2.- asynchronous call test Thu Jun 24 16:55:30 GMT+01:00 2010
FIN
0 Thread[Reference Handler,10,system]
0 Thread[Finalizer,8,system]
0 Thread[Signal Dispatcher,9,system]
0 Thread[Attach Listener,5,system]
0 Thread[RMI RenewClean-[127.0.0.1:1098],5,system]
0 Thread[GC Daemon,2,system]
0 Thread[RMI Scheduler(0),5,system]
1 Thread[main,5,main]
1 Thread[pool-1-thread-1,5,main]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100624/da5f67c0/attachment.html 


More information about the jboss-user mailing list