i have 2 classes make asynchronus method call in java ee. following link http://satishgopal.wordpress.com/2011/04/24/ejb-3-1-asynchronous-methods learn how do. when have invocate asynrnous method , having following result.
result:
info: caller method running in thread http-thread-pool-8083(5) date:1373866669346 info: start running asyncmethod in thread http-thread-pool-8083(5) info: finished running asyncmethod in thread http-thread-pool-8083(5) info: caller method running in thread http-thread-pool-8083(5) date:1373866672348
what expecting not wait asyncmethod() method invcation completed can see result asyncmethod() method invcation not handled thread. using glassfish 3.1.1 application container.
businessbean class
@managedbean @stateless public class businessbean { @asynchronous public void asyncmethod() { system.out.println("start running asyncmethod in thread "+ thread.currentthread().getname()); try { thread.sleep(3000); } catch (interruptedexception e) { e.printstacktrace(); } system.out.println("finished running asyncmethod in thread "+ thread.currentthread().getname()); } }
loginbean class
@managedbean @requestscoped public class loginbean implements serializable { private static final long serialversionuid = 1l; @managedproperty(value="#{businessbean}") businessbean businessbean; private string name; public string getname() { return name; } public void setname(string name) { this.name = name; } public void login(){ system.out.println("caller method running in thread "+thread.currentthread().getname()+" date:"+system.currenttimemillis()); businessbean.asyncmethod(); system.out.println("caller method running in thread "+thread.currentthread().getname()+" date:"+system.currenttimemillis()); } public businessbean getbusinessbean() { return businessbean; } public void setbusinessbean(businessbean businessbean) { this.businessbean = businessbean; } }
get rid of managedbean
annotation businessbean: should enterprise java bean, , @stateless
annotation.
also inject means of @ejb
:
@ejb private businessbean businessbean;
see this link further reference.
Comments
Post a Comment