{"id":28483,"date":"2014-08-13T19:00:55","date_gmt":"2014-08-13T16:00:55","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=28483"},"modified":"2014-08-13T11:42:09","modified_gmt":"2014-08-13T08:42:09","slug":"java-ee-asynchronous-constructs-and-capabilities","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html","title":{"rendered":"Java EE: Asynchronous constructs and capabilities"},"content":{"rendered":"<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/asynchronous.jpg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-28958\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/asynchronous.jpg\" alt=\"asynchronous\" width=\"310\" height=\"232\" \/><\/a><\/p>\n<h2>Introduction<\/h2>\n<p>Java EE has a number of APIs and constructs to support <strong><em>Asynchronous<\/em> <\/strong>execution. This is vital from a scalability and performance stand point.<\/p>\n<p>Let us assume\u00a02 modules which are interacting with each other. When <em>moduleA<\/em> (the sender) sends a message to <em>moduleB<\/em> (the receiver) in a <em>Synchronous<\/em> fashion, the communication takes place in the context of a <em>Single<\/em> thread i.e. the thread which initiated the communication from moduleA is <em>blocked<\/em> until moduleB responds back.<\/p>\n<p>This was a generic statement but can be extended to the context of a simple Java methods interacting with each other \u2013 in this case, a <em>synchronous<\/em> call from <em>methodA<\/em> to <em>methodB<\/em> would execute in the <em>same<\/em> <em>thread<\/em> which would be blocked until methodB returns or throws an exception.<\/p>\n<h2>Why do we need Asynchronous behavior in Java EE based applications?<\/h2>\n<p>We can further extrapolate this point to the Java EE world \u2013 be it inter server communication e.g. between web tier and EJB tier (servlets and EJBs) or a typical client server interaction \u2013 a browser interacting with a RESTful end point,\u00a0Servlets etc\u00a0\u2013\u00a0the server thread which responds to a client request always blocks until the server component responds back.<\/p>\n<p>Here is where Asynchronous execution comes into play \u2013 if the <em>server thread<\/em> processing the client request can be<em> released\/suspended<\/em> and the actual business logic is executed in a separate thread (different than that of the original one), performance and scalability can be improved immensely ! E.g. if a\u00a0HTTP listener thread allocated to listen to client requests is released immediately, then it is free to attend to requests from other clients and the business logic can be executed in a separate container thread which can then return the response via appropriate methods such as <em>java.util.concurrent.Future<\/em> object or via <em>call back handlers<\/em> registered by the client. Think from an end user perspective \u2013 <em>responsiveness<\/em> matters a lot!<\/p>\n<h2>Dive In:\u00a0Async constructs and APIs in Java EE<\/h2>\n<p>Let\u2019s take a look at few of the Async related features (APIs) in Java EE. This is not an exhaustive list \u2013 but should be a good starting point.<\/p>\n<p>Different Java EE specs have their typical ways and APIs to facilitate Async capabilities. Let\u2019s explore the below Java EE specifications<\/p>\n<ul>\n<li>JAX-RS 2.0 (Java EE 7)<\/li>\n<li>Websocket 1.0\u00a0(Java EE 7)<\/li>\n<li>Concurrency Utilities 1.0\u00a0(Java EE 7)<\/li>\n<li>EJB 3.1\u00a0(Java EE 6)<\/li>\n<li>Servlet 3.0\u00a0(Java EE 6)<\/li>\n<\/ul>\n<p><em><strong>Note<\/strong>: The code presented below is in a snippet form (for obvious reasons). The complete samples can be <a href=\"https:\/\/github.com\/abhirockzz\/JavaEEAsyncCapabilites\" target=\"_blank\">accessed here<\/a>.\u00a0<\/em><\/p>\n<h2>JAX-RS 2.0<\/h2>\n<p>Async processing of requests is a <em>new feature in 2.0 edition of JAX-RS<\/em> (new in Java EE 7). In order to execute an aysnc request using JAX-RS APIs, one needs to inject a\u00a0reference to a <strong><em>javax.ws.rs.container.AsyncResponse<\/em><\/strong> interface in the JAX-RS resource method itself. This parameter puts the request execution in async mode and the method proceeds with its execution. The <strong><em>resume<\/em> <\/strong>method on the AsynResponse object needs to be called from within a separate thread after the business logic execution is complete. One can leverage the Java EE concurrency utility features (discussed later) such as the <em>javax.enterprise.concurrent.ManagedExecutorService<\/em> in order to encapsulate the business logic as a <em>Runnable<\/em> object and submitting it to the container\u2019s executor service which takes care of the rest. No need to spawn un-managed, isolated threads on your own.<\/p>\n<pre class=\" brush:java;wrap-lines:false\">@Path(\"\/{id}\")\r\n    @GET\r\n    @Produces(\"application\/xml\")\r\n    public void asyncMethod(@Suspended AsyncResponse resp, @PathParam(\"id\") String input) {\r\n\r\n        System.out.println(\"Entered MyAsyncRESTResource\/asyncMethod() executing in thread: \"+ Thread.currentThread().getName());\r\n        mes.execute(\r\n                () -&gt; {\r\n                    System.out.println(\"Entered Async zone executing in thread: \"+ Thread.currentThread().getName());\r\n                    System.out.println(\"Simulating long running op via Thread sleep() started on \"+ new Date().toString());\r\n                    try {\r\n                        Thread.sleep(5000);\r\n                    } catch (InterruptedException ex) {\r\n                        Logger.getLogger(MyAsyncRESTResource.class.getName()).log(Level.SEVERE, null, ex);\r\n                    }\r\n                    System.out.println(\"Completed Long running op on \"+new Date().toString());\r\n                    System.out.println(\"Exiting Async zone executing in thread: \"+ Thread.currentThread().getName());\r\n\r\n                    \/\/creating a dummy instance of our model class (Student)\r\n\r\n                    Student stud = new Student(input, \"Abhishek\", \"Apr-08-1987\");\r\n                    resp.resume(Response.ok(stud).build());\r\n                }\r\n        );\r\n\r\n        System.out.println(\"Exit MyAsyncRESTResource\/asyncMethod() and returned thread \"+Thread.currentThread().getName()+\" back to thread pool\");\r\n    }<\/pre>\n<p>The <strong><em>JAX-RS Client API<\/em><\/strong> also has asynchronous capabilities but they have not been discussed in the post. They are definitely worth a look!<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h2>Websocket 1.0<\/h2>\n<p>The Websocket API is a <em>brand new addition to the Java EE<\/em> arsenal (introduced in Java EE 7). It facilitates <em>bi-directional<\/em> (both server and client initiated) communication which is also <em>full duplex<\/em> in nature (either the client or server can send messages to each other at any time).<\/p>\n<p>In order to send async messages using the Websocket API, one needs to use the <strong><em>getAsyncRemote<\/em> <\/strong>method available on the <strong><em>javax.websocket.Session<\/em><\/strong> interface. Internally, this is nothing but an instance of the nested interface of the <strong><em>javax.websocket.RemoteEnpoint<\/em><\/strong> \u2013\u00a0<strong><em>javax.websocket.RemoteEnpoint.Async<\/em><\/strong>. Calling the regular <strong><em>sendXXX<\/em> <\/strong>methods on this would result in the sending process being executed in a separate thread. This is particularly useful when you consider exchange of large messages or handling large numbers of websocket clients to whom the messages need to be sent. The method wither returns a <em>java.util.concurrent.Future<\/em> object or one can register a callback in the form of a <strong><em>javax.websocket.SendHandler<\/em><\/strong> interface implementation.<\/p>\n<pre class=\" brush:java\">public void sendMsg(@Observes Stock stock) {\r\n        System.out.println(\"Message receieved by MessageObserver --&gt; \"+ stock);\r\n        System.out.println(\"peers.size() --&gt; \"+ peers.size());\r\n        peers.stream().forEach((aPeer) -&gt; {\r\n            \/\/stock.setPrice();\r\n\r\n                            aPeer.getAsyncRemote().sendText(stock.toString(), (result) -&gt; {\r\n                System.out.println(\"Message Sent? \" + result.isOK());\r\n                System.out.println(\"Thread : \" + Thread.currentThread().getName());\r\n            });\r\n\r\n        });\r\n    }<\/pre>\n<h2>Concurrency Utilities 1.0<\/h2>\n<p>The Java EE\u00a0Concurrency Utilities is another great <em>addition\u00a0to Java EE 7<\/em>. It provides a standard way of spawning threads \u2013 the good part is that these are <em>container managed<\/em> and <em>not just isolated\/orphan threads<\/em> about which the container has no contextual information.<\/p>\n<p>In general, the\u00a0Concurrency Utilities 1.0 provide a few standard constructs for execution of asynchronous tasks in separate threads. These are as follows \u2013 <strong><em>javax.enterprise.concurrent.ManagedExecutorService\u00a0<\/em><\/strong><em> and\u00a0<\/em><strong><em>javax.enterprise.concurrent.ManagedScheduledExecutorService<\/em><\/strong>.<\/p>\n<p>In order to start a new task in a separate thread, one can use the\u00a0<em>ManagedExecutorService<\/em> interface to submit a <em>Runnable<\/em>. In addition to implementing the Runnable interface, a class can also implement the\u00a0<strong><em>javax.enterprise.concurrent.ManagedTask<\/em><\/strong> interface and provide a\u00a0\u00a0<strong><em>javax.enterprise.concurrent.ManagedTaskListener<\/em><\/strong> implementation in order to listen to life \u00a0cycle changes to the task submitted via the\u00a0ManagedExecutorService.<\/p>\n<pre class=\" brush:java;wrap-lines:false\">@Override\r\n    protected void doGet(HttpServletRequest request, HttpServletResponse response)\r\n            throws ServletException, IOException {\r\n\r\n        System.out.println(\"Enter AConcurrencyUtilsExample\/doGet executing in thread \"+ Thread.currentThread().getName());\r\n        System.out.println(\"initiating task . . . \");\r\n        mes.execute(new AManagedTask());\r\n        System.out.println(\"Exit AConcurrencyUtilsExample\/doGet and returning thread \"+ Thread.currentThread().getName() +\" back to pool\");\r\n    }<\/pre>\n<h2>Servlet 3.0<\/h2>\n<p>Asynchronous HTTP was introduced in Servlet 3.0 (part of <em>Java EE 6<\/em>) which basically provided the capability to execute the request in separate thread and suspend the original thread which handled the client invocation.<\/p>\n<p>The key player here is the <strong><em>javax.servlet.AsyncContext<\/em><\/strong> interface. In order to initiate\u00a0asynchronous processing, the <strong><em>startAsync<\/em> <\/strong>method of the <strong><em>java.servlet.ServletRequest<\/em><\/strong>\u00a0interface is called. In order to execute the core logic, a <em>java.lang.Runnable<\/em> object needs to be submitted to the start method of the AsyncContext interface.\u00a0One can choose to attach a listener by implementing the <strong><em>javax.servlet.AsyncListener<\/em><\/strong> in order to receive <em>callback<\/em> notifications during specific times of the Async task execution.<\/p>\n<pre class=\" brush:java;wrap-lines:false\">@Override\r\n\r\n    public void doGet(HttpServletRequest req, HttpServletResponse resp) {\r\n\r\n        PrintWriter writer = null;\r\n        try {\r\n            writer = resp.getWriter();\r\n        } catch (IOException ex) {\r\n            Logger.getLogger(MyAsyncServlet.class.getName()).log(Level.SEVERE, null, ex);\r\n        }\r\n        \/\/System.out.println(\"entered doGet()\");\r\n        writer.println(\"ENTERING ... \" + MyAsyncServlet.class.getSimpleName() + \"\/doGet()\");\r\n        writer.println(\"Executing in Thread: \" + Thread.currentThread().getName());\r\n        \/\/step 1\r\n        final AsyncContext asyncContext = req.startAsync();\r\n\r\n        \/\/step 2\r\n        asyncContext.addListener(new CustomAsyncHandler(asyncContext));\r\n\r\n        \/\/step 3\r\n        asyncContext.start(\r\n                () -&gt; {\r\n                    PrintWriter logger = null;\r\n                    try {\r\n                        logger = asyncContext.getResponse().getWriter();\r\n                    } catch (IOException ex) {\r\n                        Logger.getLogger(MyAsyncServlet.class.getName()).log(Level.SEVERE, null, ex);\r\n                    }\r\n\r\n                    logger.println(\"Long running Aync task execution started : \" + new Date().toString());\r\n\r\n                    logger.println(\"Executing in Thread: \" + Thread.currentThread().getName());\r\n                    try {\r\n                        Thread.sleep(5000);\r\n                    } catch (InterruptedException e) {\r\n                        Logger.getLogger(MyAsyncServlet.class.getName()).log(Level.SEVERE, null, e);\r\n                    }\r\n\r\n                    logger.println(\"Long task execution complete : \" + new Date().toString());\r\n\r\n                    logger.println(\"Calling complete() on AsyncContext\");\r\n\r\n                    \/\/step 4\r\n                    asyncContext.complete();\r\n                }\r\n        );\r\n\r\n        writer.println(\"EXITING ... \" + MyAsyncServlet.class.getSimpleName() + \"\/doGet() and returning initial thread back to the thread pool\");\r\n\r\n    }<\/pre>\n<h2>EJB 3.1<\/h2>\n<p>Typically, (prior to EJB 3.1) EJB Message Driven Beans were\u00a0used to fulfill async related requirements. A MDB bean listens to messages sent to a <em>javax.jms.Destination<\/em> (a <em>Queue<\/em> or <em>Topic<\/em>) and executes the required business logic \u2013 this might be anything from sending an email to initiating an order processing task. The important thing to understand is that the client which sends the message to the Queue in the first place is <em>unaware<\/em> of the MDB (<em>decoupled<\/em>) and <em>does not have to wait\/remain blocked<\/em> until the end of the job (email receipt or order processing confirmation).<\/p>\n<p>EJB 3.1 (part of <em>Java EE 6<\/em>)\u00a0introduced the <strong><em>javax.ejb.Asynchronous<\/em><\/strong> annotation. This can be placed on a EJB Session bean (Stateless, Stateful or Singleton) <em>class\u00a0<\/em>(makes all the methods Asynchronous) or at the <em>method<\/em> level itself \u2013 in case fine grained control is needed. A method with the @Asynchronous annotation can either return <em>void<\/em> (fire and forget) or an instance of <em>java.util.concurrent.Future<\/em> if the async method result needs to be tracked \u2013 this can be done by calling the <strong><em>Future.get()<\/em><\/strong> \u2013 the thing to note\u00a0is that the <strong><em>get<\/em> <\/strong>method itself is <em>blocking<\/em> in nature.<\/p>\n<pre class=\" brush:java;wrap-lines:false\">@Asynchronous\r\n        public Future&lt;String&gt; asyncEJB2(){\r\n\r\n        System.out.println(\"Entered MyAsyncEJB\/asyncEJB2()\");\r\n       System.out.println(\"MyAsyncEJB\/asyncEJB2() Executing in thread: \"+ Thread.currentThread().getName());\r\n        System.out.println(\"Pretending as if MyAsyncEJB\/asyncEJB2() is doing something !\");\r\n        try {\r\n            Thread.sleep(5000);\r\n        } catch (InterruptedException ex) {\r\n            java.util.logging.Logger.getLogger(MyAsyncEJB.class.getName()).log(Level.SEVERE, null, ex);\r\n        }\r\n\r\n        System.out.println(\"Exiting MyAsyncEJB\/asyncEJB2()\");\r\n        return new AsyncResult(\"Finished Executing on \"+ new Date().toString());\r\n\r\n    }<\/pre>\n<p>This was a rather brief preview of Java EE capabilities. These APIs and specifications are functionally rich and it is hard cover all of them via a blog post! I hope this piques your interest and gives you a starting point to explore further.<\/p>\n<p>Cheers!<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"http:\/\/abhirockzz.wordpress.com\/2014\/07\/29\/java-ee-asynchronous-constructs-and-capabilities\/\">Java EE: Asynchronous constructs and capabilities<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Abhishek Gupta at the <a href=\"http:\/\/abhirockzz.wordpress.com\/\">Object Oriented.. <\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Java EE has a number of APIs and constructs to support Asynchronous execution. This is vital from a scalability and performance stand point. Let us assume\u00a02 modules which are interacting with each other. When moduleA (the sender) sends a message to moduleB (the receiver) in a Synchronous fashion, the communication takes place in the &hellip;<\/p>\n","protected":false},"author":545,"featured_media":112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-28483","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java EE: Asynchronous constructs and capabilities<\/title>\n<meta name=\"description\" content=\"Introduction Java EE has a number of APIs and constructs to support Asynchronous execution. This is vital from a scalability and performance stand point.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java EE: Asynchronous constructs and capabilities\" \/>\n<meta property=\"og:description\" content=\"Introduction Java EE has a number of APIs and constructs to support Asynchronous execution. This is vital from a scalability and performance stand point.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"http:\/\/www.facebook.com\/100000586869380\" \/>\n<meta property=\"article:published_time\" content=\"2014-08-13T16:00:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Abhishek Gupta\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/abhi_tweeter\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Abhishek Gupta\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/08\\\/java-ee-asynchronous-constructs-and-capabilities.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/08\\\/java-ee-asynchronous-constructs-and-capabilities.html\"},\"author\":{\"name\":\"Abhishek Gupta\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/ef37bd58f3ae6f6504852858ad1d7cd7\"},\"headline\":\"Java EE: Asynchronous constructs and capabilities\",\"datePublished\":\"2014-08-13T16:00:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/08\\\/java-ee-asynchronous-constructs-and-capabilities.html\"},\"wordCount\":1248,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/08\\\/java-ee-asynchronous-constructs-and-capabilities.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/08\\\/java-ee-asynchronous-constructs-and-capabilities.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/08\\\/java-ee-asynchronous-constructs-and-capabilities.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/08\\\/java-ee-asynchronous-constructs-and-capabilities.html\",\"name\":\"Java EE: Asynchronous constructs and capabilities\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/08\\\/java-ee-asynchronous-constructs-and-capabilities.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/08\\\/java-ee-asynchronous-constructs-and-capabilities.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"datePublished\":\"2014-08-13T16:00:55+00:00\",\"description\":\"Introduction Java EE has a number of APIs and constructs to support Asynchronous execution. This is vital from a scalability and performance stand point.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/08\\\/java-ee-asynchronous-constructs-and-capabilities.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/08\\\/java-ee-asynchronous-constructs-and-capabilities.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/08\\\/java-ee-asynchronous-constructs-and-capabilities.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"java-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/08\\\/java-ee-asynchronous-constructs-and-capabilities.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Java EE: Asynchronous constructs and capabilities\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/ef37bd58f3ae6f6504852858ad1d7cd7\",\"name\":\"Abhishek Gupta\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3f3fc8e83d92bec29f7cb54bba3d5043d138c479a66a4711483bc6b4d95ae37c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3f3fc8e83d92bec29f7cb54bba3d5043d138c479a66a4711483bc6b4d95ae37c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3f3fc8e83d92bec29f7cb54bba3d5043d138c479a66a4711483bc6b4d95ae37c?s=96&d=mm&r=g\",\"caption\":\"Abhishek Gupta\"},\"sameAs\":[\"http:\\\/\\\/abhirockzz.wordpress.com\\\/\",\"http:\\\/\\\/www.facebook.com\\\/100000586869380\",\"http:\\\/\\\/in.linkedin.com\\\/pub\\\/abhishek-gupta\\\/27\\\/331\\\/866\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/abhi_tweeter\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/abhishek-gupta\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java EE: Asynchronous constructs and capabilities","description":"Introduction Java EE has a number of APIs and constructs to support Asynchronous execution. This is vital from a scalability and performance stand point.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html","og_locale":"en_US","og_type":"article","og_title":"Java EE: Asynchronous constructs and capabilities","og_description":"Introduction Java EE has a number of APIs and constructs to support Asynchronous execution. This is vital from a scalability and performance stand point.","og_url":"https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"http:\/\/www.facebook.com\/100000586869380","article_published_time":"2014-08-13T16:00:55+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Abhishek Gupta","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/abhi_tweeter","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Abhishek Gupta","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html"},"author":{"name":"Abhishek Gupta","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/ef37bd58f3ae6f6504852858ad1d7cd7"},"headline":"Java EE: Asynchronous constructs and capabilities","datePublished":"2014-08-13T16:00:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html"},"wordCount":1248,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html","url":"https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html","name":"Java EE: Asynchronous constructs and capabilities","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","datePublished":"2014-08-13T16:00:55+00:00","description":"Introduction Java EE has a number of APIs and constructs to support Asynchronous execution. This is vital from a scalability and performance stand point.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","width":150,"height":150,"caption":"java-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2014\/08\/java-ee-asynchronous-constructs-and-capabilities.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Java EE: Asynchronous constructs and capabilities"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/ef37bd58f3ae6f6504852858ad1d7cd7","name":"Abhishek Gupta","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3f3fc8e83d92bec29f7cb54bba3d5043d138c479a66a4711483bc6b4d95ae37c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3f3fc8e83d92bec29f7cb54bba3d5043d138c479a66a4711483bc6b4d95ae37c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3f3fc8e83d92bec29f7cb54bba3d5043d138c479a66a4711483bc6b4d95ae37c?s=96&d=mm&r=g","caption":"Abhishek Gupta"},"sameAs":["http:\/\/abhirockzz.wordpress.com\/","http:\/\/www.facebook.com\/100000586869380","http:\/\/in.linkedin.com\/pub\/abhishek-gupta\/27\/331\/866","https:\/\/x.com\/https:\/\/twitter.com\/abhi_tweeter"],"url":"https:\/\/www.javacodegeeks.com\/author\/abhishek-gupta"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/28483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/545"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=28483"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/28483\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/112"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=28483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=28483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=28483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}