Sunteți pe pagina 1din 6

7/17/2014 FitProgrammer@Work: Java EE 6 - Part 7 - Writing Asynchronous Session Beans

http://rwatsh.blogspot.in/2013/03/java-ee-6-part-7-writing-asynchronous.html 1/6
My "pensive" - where i simply siphon the excess thoughts from my mind, pour them into the basin (of cloud storage), and examine
them at leisure.
FitProgrammer@Work
Friday, March 15, 2013
Java EE 6 - Part 7 - Writing Asynchronous Session Beans
This is a very useful enhancement in EJB 3.1 that lets the client make a server method call asynchronously.
In the past we needed to write a lot of code to achieve the same result. The client used to create a
temporary JMS queue destination and pass it to the server in the remote method call and the server did its
task asynchronously and used the temporary queue to send its response back to client. This has now been
taken care of by Java EE 6 framework with the introduction of the @Asynchronous annotations for session
beans.
Project: EJB31-Common
package helloworld.beans;
import java.util.concurrent.Future;
import javax.ejb.Remote;
/**
* Interface for the asynch session bean.
*
* @author rwatsh
*/
@Remote
public interface HelloEjbAsynchronousRemote {
Future ejbAsynchronousSayHello(String name);

}
Project: EJB31-ejb
package helloworld.beans;
import java.util.Date;
import java.util.concurrent.Future;
import javax.ejb.AsyncResult;
import javax.ejb.Asynchronous;
import javax.ejb.Stateless;
/**
* Stateless session bean with a long running task executed asynchronously.
*
* @author rwatsh
*/
@Stateless
public class HelloEjbAsynchronous implements HelloEjbAsynchronousRemote {
@Asynchronous
@Override
public Future ejbAsynchronousSayHello(String name) {
System.out.println(new Date().toString() + " - Begin -
HelloEjbAsynchronous.ejbAsynchronousSayHello: " + name);
// simulate some delay
try {
Thread.sleep(50000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(new Date().toString() + " - End - HelloEjbAsynchronous.ejbAsynchronousSayHello:
" + name);
return new AsyncResult("Hello " + name);
}
}

If you like the content,
support us by making
a donation
Site visitors map

114,265
Total Pageviews
0
My Blog List
Boing Boing Blog
The Mystery of the
Disappearing Airmen
42 minutes ago
In Relation To -
Bloggers
[Comment] Weld
1.1.7.Final Released
1 hour ago
New Urban
Legends
The Well to Hell
2 hours ago
InfoQ
Personalized Feed
for Unregistered
User - Registered
to upgrade!
Streams Library
Brings Lazy Evaluation
and Functional-style to
C++14
3 hours ago
JetBrains IntelliJ
IDEA Blog
The Backspace Key
Gets Smarter in IntelliJ
IDEA 14 EAP
4 hours ago
java.net Weblogs
Getting Started with
Docker (Tech Tip #39)
11 hours ago
Watsh Rajneesh
Follow
View my complete profile
About Me
Follow @rwatsh
Twitter
Resolution for No buffer space
available (maximum connections
reached?): JVM_Bind issue
I hit this issue recently which occurred
on only one windows 7 host. The error
was caused by this hard to guess
reason ( http://support.mic...
Using Quartz Scheduler in
a Java EE Web Application
At times, you may have
wanted to perform some
action periodically in your
web application. Quartz is an enterprise
grade scheduler which can...
Integrating Java and PHP:
the Web Services way
Recently on a project, we
were faced with the
question: do we put the
business logic in the web tier (which was
written in PHP 4.7.3) or do ...
Installing VMware Tools on Ubuntu
Guest OS
VMware Tools are binaries that are
guest OS dependent and need to be
installed on the VM after the guest OS
has been installed. The tools ar...
Understanding RRDTool
RRD Tool is a product that grew out of
MRTG . It creates a very compact
database structure for the storage of
periodic data, such as is ...
Emma vs Cobertura
The 2 open source Java code coverage
tools that are the best among the lot are
cobertura and emma. Both have their
own pros and cons. Cobe...
Understanding Cable
Broadband Technology
Below is an introduction to
the terms, concepts and
summary of the features of
DOCSIS standard versions which i have
compiled from several ...
Using NPIV port for RDM disk access in
VMware vSphere
Following are the steps to create NPIV
port on an adapter (only tested with
Brocade HBAs) on a host with VMware
vSphere ESX/ESXi hypervisor...
Popular Posts
0

More

Next Blog Create Blog
7/17/2014 FitProgrammer@Work: Java EE 6 - Part 7 - Writing Asynchronous Session Beans
http://rwatsh.blogspot.in/2013/03/java-ee-6-part-7-writing-asynchronous.html 2/6
Newer Post Older Post Home
Subscribe to: Post Comments (Atom)
Posted by Watsh Rajneesh at 2:25 PM
Project: StandAloneApp
package standaloneapp;
import helloworld.beans.HelloEjbAsynchronousRemote;
import java.util.concurrent.Future;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* This client can be a SwingWorker waiting for server task to complete and
* respond asynchronously while the client carries on with other UI tasks.
*
* @author rwatsh
*/
public class AsyncClient {
private static HelloEjbAsynchronousRemote helloWorldBean;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
System.err.println("standaloneapp.Main.main: Stand-alone App started");
String jndiPath = "java:global/EJB31/EJB31-ejb/HelloEjbAsynchronous";
try {
Context ctx = new InitialContext();
System.out.println("standaloneapp.Main.main: looking up bean at: "
+ jndiPath);
helloWorldBean = (HelloEjbAsynchronousRemote) ctx.lookup(jndiPath);
System.out.println("standaloneapp.Main.main: found HelloWorldBean: "
+ helloWorldBean);
System.out.println("standaloneapp.Main.main: calling sayHello");
Future future = helloWorldBean.ejbAsynchronousSayHello("Watsh");
while (!future.isDone()) {
Thread.sleep(10000);
System.out.println("Doing some other client tasks and waiting for server to respond");
}
String greeting = (String) future.get();
System.out.println("standaloneapp.Main.main: HelloWorldBean said: "
+ greeting);
} catch (NamingException ex) {
System.err.println(
"standaloneapp.Main.main: Could not find HelloWorldBeanRemote");
System.err.println("standaloneapp.Main.main: JNDI path used for lookup: " + jndiPath);
ex.printStackTrace();
}
}
}
Recommend this on Google
Post a Comment
Create a Link
No comments:
Links to this post
JetBrains News
dotPeek 1.2 Is
Released
1 day ago
film babble blog
Blu Ray/DVD Review:
The Weird Scarlett
Johansson Flick
UNDER THE SKIN
1 day ago
Java
Three.js Essentials
2 days ago
YouTube :: Most
Discussed Videos
- This Month
Last Week Tonight
with John Oliver:
Wealth Gap (HBO)
3 days ago
Otaku, Cedric's
weblog
A Rubiks cube
implementation in
Three.js
3 days ago
Coding the
Architecture
One view or many?
1 week ago
Codedependent
Presenting Presenting:
Tips and Thoughts on
Preparing and Giving
Engaging
Presentations
1 week ago
The Java Posse
Java Posse #455
2 weeks ago
Curious Creature
Google I/O 2014
Slides and Demo
2 weeks ago
Pushing Pixels
At the intersection of
the physical and
digital interview with
Michael Goldman
3 weeks ago
Raible Designs
Father's Day Weekend
on The Arkansas River
4 weeks ago
James Carr
Installing
Elasticsearch Plugins
on Graylog2
4 weeks ago
The Java(tm)
Specialists'
Newsletter
Throwing Checked
Exceptions From
Lambdas
5 weeks ago
BitWorking | Joe
Gregorio
No more JS
Using TestNG with Emma for automating
test code coverage report generation
TestNG and Emma can be used
together to automate the generation of
code coverage report after every test
run in the ANT builld script. Follo...
Charting the web with Cewolf/JFreeChart
- Producing Time Series plots
I recently had an opportunity to use the
Cewolf 1.0 at work for some Time Series
plots (a variant of the XY Chart, shown
in the figure abov...
2014 (39)
2013 (48)
December (1)
November (3)
October (24)
July (2)
June (1)
May (2)
March (13)
Toastmasters Table Topics
Life as an Object
Toastmasters speech 1
Virtual Networks
Java EE 6 - Part 8 -
Transactions
Java EE 6 - Part 7 - Writing
Asynchronous Session ...
Java EE 6 - Part 6 - Writing
EJB TimerService and ...
Java EE 6 - Part 5 - Writing
Message Driven Beans
Java EE 6 - Part 4 - Writing
JMS Message
Producers...
Java EE 6 - Part 3 - Writing
Singleton Session Bea...
Java EE 6 - Part 2 - Writing
Stateful Session Bean...
Java EE 6 - Part 1 - Writing
Stateless Session Bea...
A Quick VBScript Tutorial
Java 7 Locale Changes
impacting
Double.parseDouble...
Linux Mint 14 XFCE
notebook
January (2)
2012 (19)
2011 (12)
2010 (2)
2009 (13)
2008 (10)
2007 (19)
2006 (32)
Blog Archive
AJAX (3)
BaseApp (1)
Labels
7/17/2014 FitProgrammer@Work: Java EE 6 - Part 7 - Writing Asynchronous Session Beans
http://rwatsh.blogspot.in/2013/03/java-ee-6-part-7-writing-asynchronous.html 3/6
frameworks
2 months ago
JetBrains Zone -
For IntelliJ IDEA,
TeamCity &
ReSharper users
What Makes IntelliJ
IDEA Different
2 months ago
Software is too
expensive to build
cheaply...
Object equality is
context sensitive
3 months ago
Blogging Roller
Talking Usergrid at
ApacheCon 2014
4 months ago
New DivaBlog
Making friends, hiring
and buying
chocolate...
4 months ago
The Goldfish
Chronicles
Knowing If Your Drive
Needs HDD Recovery
7 months ago
Simple Thoughts -
Java and Web
Blog
How to install and run
latest s3fs on CentOS
5.5
8 months ago
Alef Arendsen
Elder Blossom Syrup
11 months ago
Vclav Pech
The winner takes it all
1 year ago
Rick Hightower's
Sleepless Night in
Tucson
Blogging random
thoughts.... Where is
Rick?
1 year ago
cat /dev/random
Solar -- one month in
1 year ago
Yahoo! News -
Oddly Enough
10 years later, Star
Wars Kid speaks
1 year ago
Geertjan's Blog
Systems Biology
Network Visualization
on the NetBeans
Platform
1 year ago
CodeFeed
OSXdd Dead Slow
1 year ago
agile j2ee: rod
johnson's blog
Introducing Hyperic
book review (4)
boxing (1)
BPEL (1)
Cable Broadband (1)
Certification (1)
Code Coverage (1)
Design Patterns (4)
Displaytag (1)
DOCSIS (1)
DWR (1)
experiences (5)
GoF (3)
IDE (1)
Java EE (11)
Java SE (3)
JSP (1)
Kempo Karate (1)
Maynard (1)
Memory Leak (1)
network management (1)
PHP (1)
priority inversions (1)
Programming Practices (1)
Quartz (1)
RTOS (1)
SCM (1)
Seam (1)
snmp (1)
stallings (1)
Sun certifications (5)
unit testing (1)
USA (1)
vblog (1)
Webservices (3)
Subscribe To
Posts
Comments
7/17/2014 FitProgrammer@Work: Java EE 6 - Part 7 - Writing Asynchronous Session Beans
http://rwatsh.blogspot.in/2013/03/java-ee-6-part-7-writing-asynchronous.html 4/6
5.0
1 year ago
Found Cameras
and Orphan
Pictures
Big Sur, California
1 year ago
The Disco Blog
Continuous Android
testing with Guard
1 year ago
Abhi On Java
Integrate Jersey and
Spring
2 years ago
Buzz Out Loud
from CNET
Buzz Out Loud 1588:
Loved the show
(Podcast)
2 years ago
Amit Kumar Saha's
Blog
Kung Fu Panda 2
2011 720P BluRay
DTS x264-AVCHD
2 years ago
bLaugh - The
(un)Official Comic
of the
Blogosphere
Commune?
2 years ago
The Aquarium
A status on JAX-RS
2.0. Early Draft.
2 years ago
{Complexity}
Korean fashion style
following KPOP weave
2 years ago
Chaotic Java
Testing Firewall
2 years ago
Jonathan
Schwartz's Blog
Jersey Micro
Benchmarking
Framework
2 years ago
Stephen
Colebourne's
Weblog
Blog moved!!!
2 years ago
Stuck in the
middle
New home for this blog
3 years ago
Stuff White People
Like
Adorn your wall with
this really cool poster.
3 years ago
Headius
JRuby on Rails on
Amazon Elastic
Beanstalk
3 years ago
7/17/2014 FitProgrammer@Work: Java EE 6 - Part 7 - Writing Asynchronous Session Beans
http://rwatsh.blogspot.in/2013/03/java-ee-6-part-7-writing-asynchronous.html 5/6
Junior developer
How to use JavaCC
with JRuby
3 years ago
Smalltalk Tidbits,
Industry Rants
Smalltalk Daily
10/15/10: Convenient
Dialog Methods
3 years ago
Mark McLaren's
Weblog
jsoup reads hCard
really easily
3 years ago
Neal Gafter's blog
A couple of comments
on Defender Methods
3 years ago
Jim Grisanzio
Tokyo BarCamp 2010:
Photos
4 years ago
Cliff Click Jr.s
Blog
Old Blog, New
Location
4 years ago
James Gosling: on
the Java Road
Moving my blog....
4 years ago
Simon Phipps,
SunMink
Why H.264 Must
Be Avoided
4 years ago
Skrocki's Blog
Exiting the Sun Ride
4 years ago
bedeviled mojo
slop
Major League Gaming
+ Agora Games =
Crazy Delicious
4 years ago
Parleys.com
Spring Dynamic
Modules for OSGi
5 years ago
Vincent Massol
Think Tank
Moving Blog
5 years ago
The Dilbert Blog
Blog relocation
6 years ago
Stuff Educated
Black People Like
Coming Soon
6 years ago
Enter The JBoss
Matrix
Meeting Real Life
Security Needs with
the Java EE
specifications
6 years ago
7/17/2014 FitProgrammer@Work: Java EE 6 - Part 7 - Writing Asynchronous Session Beans
http://rwatsh.blogspot.in/2013/03/java-ee-6-part-7-writing-asynchronous.html 6/6
Hans Muller's Blog
Traveling Under the
Watchful Eyes of the
Big Brotherhood
11 years ago
Kohsuke
Kawaguchi's Blog
44 years ago
Join this site
with Google Friend Connect
Members (7)
Already a member? Sign in
Followers
2006-2014 Watsh Rajneesh. All Rights Reserved.
. Awesome Inc. template. Template images by chuwy. Powered by Blogger.

S-ar putea să vă placă și