SlideShare a Scribd company logo
Web Component Development
with Servlet & JSP Technologies
(EE 6)
Module-11: Asynchronous Servlets and Clients
www.webstackacademy.com
Objectives
Upon completion of this module, you should be able
to:
● Use the Asynchronous Servlet mechanism
● Use JavaScript to send an HTTP request from a client
● Process an HTTP response entirely in JavaScript
● Combine these techniques to create the effect of
server-push
www.webstackacademy.com
Relevance
Discussion – The following questions are relevant to
understanding what technologies are available for
developing web applications and the limitations of
those technologies:
● What happens if the response to an HTTP request
cannot be made until a message is rteceived from a
third party? Must the servlet thread be blocked
indefinitely?
● Suppose dozens of clients are cooperating, for
example, in a chat room. Must a request from every
client be blocked waiting until one client triggers an
update?
www.webstackacademy.com
Asynchronous Servlets
Java EE 6 adds the option to perform request processing
asynchronously. If this is done, then the servlet
execution thread can be freed up to service requests
from other clients, and the generation of the response
may be performed in another thread, for example the
thread that creates the trigger condition that allows the
response to be prepared.
www.webstackacademy.com
Asynchronous Servlets
Java EE 6 adds the option to perform request processing
asynchronously. If this is done, then the servlet
execution thread can be freed up to service requests
from other clients, and the generation of the response
may be performed in another thread, for example the
thread that creates the trigger condition that allows the
response to be prepared.
www.webstackacademy.com
Separating Request Receipt from Response
Generation
● To allow for separation of request from response generation, the
servlet API provides a class called AsyncContext. A servlet that
wishes to hand off response generation to another thread can
obtain an AsyncContext object and pass this to another thread,
perhaps using a queue.
● The AsyncContext object provides access to the original
HttpServletRequest and HttpServletResponse objects.
● RequestDispatcher, is achieved using one of serveral dispatch
methods in the AsyncContext itself.
www.webstackacademy.com
Asynchronous Servlet Example
protected void processRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
AsyncContext ac = request.startAsync();
handler.addJob(ac);
}
www.webstackacademy.com
Forwarding and Filtering
Asynchronous handlers are permitted to dispatch or forward their
processing to other servlets or JSPs, including those that are not
asynchronous (that is, they do not carry the asyncSupported=true
element in the annotation). This allows a standard response page to
be used as a view for both synchronous and asynchronous responses.
Filters can be invoked on asynchronous invocations too. If the
AsyncContext.dispatch call is used on a matching URL, the dispatcher
type will by ASYNC
www.webstackacademy.com
Asynchronous Listeners
The AsyncListener interface must be implemented by the listener
that will be notified when these situations arise. The interface
defines four listener methods:
● onComplete(AsyncEvent)
● onError(AsyncEvent)
● onTimeout(AsyncEvent)
● onStartAsync(AsyncEvent)
www.webstackacademy.com
Asynchronous JavaScript Clients(AJAX)
AJAX is a technique for creating fast and dynamic web
pages.
AJAX allows web pages to be updated asynchronously by
exchanging small amounts of data with the server behind
the scenes. This means that it is possible to update parts
of a web page, without reloading the whole page.
www.webstackacademy.com
Combining Asynchronous Servlets With Asynchronous JavaScript
● Consider a page containing JavaScript code that makes an
asynchronous request for update from the server, and a server-side
implementation that uses the asynchronous servlet techniques.
● Now, if the server does not choose to respond for several minutes, the
user is not inconvenienced, as the body of the page is operating
normally.
● Similarly, because of the use of asynchronous servlet execution, the
resource load on the server is minimized. Consequently, the response
may be sent at a time convenient to the server, and the effect of
server-push is achieved in an architecturally manageable way.
Web Stack Academy (P) Ltd
#83, Farah Towers,
1st floor,MG Road,
Bangalore – 560001
M: +91-80-4128 9576
T: +91-98862 69112
E: info@www.webstackacademy.com

More Related Content

What's hot (20)

PPTX
Salesforce DUG - Queueable Apex
Akshay Varu
 
ODP
Java concurrency
Srinivasan Raghvan
 
PDF
React + Mobile
antriss
 
PPT
Ajax
devisp
 
PDF
Building Asynchronous Microservices with Armeria
LINE Corporation
 
PPTX
Ajax Technology
Zia_Rehman
 
PDF
Akka - Developing SEDA Based Applications
Benjamin Darfler
 
PPTX
Async js
Alexandr Skachkov
 
PPT
Ajax Patterns : Periodic Refresh & Multi Stage Download
Eshan Mudwel
 
ODP
Fluxxor react library
Karthick Kumar
 
PPTX
Ajax and ASP.NET AJAX
Julie Iskander
 
PPT
Simple Java component in Mule
Christian Hipolito
 
PDF
Introduction to React, Flux, and Isomorphic Apps
Federico Torre
 
PPTX
Gatling Tool in Action at Devoxx 2012
slandelle
 
PDF
MMS Automation In Action!
MongoDB
 
PDF
Building RESTtful services in MEAN
Madhukara Phatak
 
PPTX
Increase automation to rest
Shivaling Sannalli
 
PDF
Stripe con 2021 UI stack
MaximeRainville1
 
Salesforce DUG - Queueable Apex
Akshay Varu
 
Java concurrency
Srinivasan Raghvan
 
React + Mobile
antriss
 
Ajax
devisp
 
Building Asynchronous Microservices with Armeria
LINE Corporation
 
Ajax Technology
Zia_Rehman
 
Akka - Developing SEDA Based Applications
Benjamin Darfler
 
Ajax Patterns : Periodic Refresh & Multi Stage Download
Eshan Mudwel
 
Fluxxor react library
Karthick Kumar
 
Ajax and ASP.NET AJAX
Julie Iskander
 
Simple Java component in Mule
Christian Hipolito
 
Introduction to React, Flux, and Isomorphic Apps
Federico Torre
 
Gatling Tool in Action at Devoxx 2012
slandelle
 
MMS Automation In Action!
MongoDB
 
Building RESTtful services in MEAN
Madhukara Phatak
 
Increase automation to rest
Shivaling Sannalli
 
Stripe con 2021 UI stack
MaximeRainville1
 

Similar to Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 11 - Asynchronous Servlets and Clients (20)

PPT
Ajax
guest873a50
 
PDF
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...
WebStackAcademy
 
PPTX
IP UNIT III PPT.pptx
ssuser92282c
 
PPT
Presentation on java servlets
Aamir Sohail
 
PPTX
Reverse ajax in 2014
Nenad Pecanac
 
PDF
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Tushar B Kute
 
DOCX
Asynchronous reading and writing http r equest
Pragyanshis Patnaik
 
PPT
Ajax and PHP
John Coggeshall
 
PDF
Liit tyit sem 5 enterprise java unit 1 notes 2018
tanujaparihar
 
PPT
Servlet 01
Bharat777
 
PPTX
Java Servlet
Yoga Raja
 
PPT
Servlet ppt by vikas jagtap
Vikas Jagtap
 
PPTX
SERVLET in web technolgy engineering.pptx
ARUNKUMARM230658
 
PPT
jQuery Ajax
Anand Kumar Rajana
 
PPTX
J2ee servlet
vinoth ponnurangam
 
PPT
Ajax Ppt 1
JayaPrakash.m
 
PDF
C sharp and asp.net interview questions
Akhil Mittal
 
PDF
Ajax & Reverse Ajax Presenation
Rishabh Garg
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...
WebStackAcademy
 
IP UNIT III PPT.pptx
ssuser92282c
 
Presentation on java servlets
Aamir Sohail
 
Reverse ajax in 2014
Nenad Pecanac
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Tushar B Kute
 
Asynchronous reading and writing http r equest
Pragyanshis Patnaik
 
Ajax and PHP
John Coggeshall
 
Liit tyit sem 5 enterprise java unit 1 notes 2018
tanujaparihar
 
Servlet 01
Bharat777
 
Java Servlet
Yoga Raja
 
Servlet ppt by vikas jagtap
Vikas Jagtap
 
SERVLET in web technolgy engineering.pptx
ARUNKUMARM230658
 
jQuery Ajax
Anand Kumar Rajana
 
J2ee servlet
vinoth ponnurangam
 
Ajax Ppt 1
JayaPrakash.m
 
C sharp and asp.net interview questions
Akhil Mittal
 
Ajax & Reverse Ajax Presenation
Rishabh Garg
 
Ad

More from WebStackAcademy (20)

PDF
Webstack Academy - Course Demo Webinar and Placement Journey
WebStackAcademy
 
PDF
WSA: Scaling Web Service to Handle Millions of Requests per Second
WebStackAcademy
 
PDF
WSA: Course Demo Webinar - Full Stack Developer Course
WebStackAcademy
 
PDF
Career Building in AI - Technologies, Trends and Opportunities
WebStackAcademy
 
PDF
Webstack Academy - Internship Kick Off
WebStackAcademy
 
PDF
Building Your Online Portfolio
WebStackAcademy
 
PDF
Front-End Developer's Career Roadmap
WebStackAcademy
 
PDF
Angular - Chapter 9 - Authentication and Authorization
WebStackAcademy
 
PDF
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
PDF
Angular - Chapter 6 - Firebase Integration
WebStackAcademy
 
PDF
Angular - Chapter 5 - Directives
WebStackAcademy
 
PDF
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
 
PDF
Angular - Chapter 3 - Components
WebStackAcademy
 
PDF
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
PDF
Angular - Chapter 1 - Introduction
WebStackAcademy
 
PDF
JavaScript - Chapter 10 - Strings and Arrays
WebStackAcademy
 
PDF
JavaScript - Chapter 15 - Debugging Techniques
WebStackAcademy
 
PDF
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 
PDF
JavaScript - Chapter 13 - Browser Object Model(BOM)
WebStackAcademy
 
PDF
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
Webstack Academy - Course Demo Webinar and Placement Journey
WebStackAcademy
 
WSA: Scaling Web Service to Handle Millions of Requests per Second
WebStackAcademy
 
WSA: Course Demo Webinar - Full Stack Developer Course
WebStackAcademy
 
Career Building in AI - Technologies, Trends and Opportunities
WebStackAcademy
 
Webstack Academy - Internship Kick Off
WebStackAcademy
 
Building Your Online Portfolio
WebStackAcademy
 
Front-End Developer's Career Roadmap
WebStackAcademy
 
Angular - Chapter 9 - Authentication and Authorization
WebStackAcademy
 
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
Angular - Chapter 6 - Firebase Integration
WebStackAcademy
 
Angular - Chapter 5 - Directives
WebStackAcademy
 
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
 
Angular - Chapter 3 - Components
WebStackAcademy
 
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
Angular - Chapter 1 - Introduction
WebStackAcademy
 
JavaScript - Chapter 10 - Strings and Arrays
WebStackAcademy
 
JavaScript - Chapter 15 - Debugging Techniques
WebStackAcademy
 
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
WebStackAcademy
 
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
Ad

Recently uploaded (20)

PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Digital Circuits, important subject in CS
contactparinay1
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 

Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 11 - Asynchronous Servlets and Clients

  • 1. Web Component Development with Servlet & JSP Technologies (EE 6) Module-11: Asynchronous Servlets and Clients
  • 2. www.webstackacademy.com Objectives Upon completion of this module, you should be able to: ● Use the Asynchronous Servlet mechanism ● Use JavaScript to send an HTTP request from a client ● Process an HTTP response entirely in JavaScript ● Combine these techniques to create the effect of server-push
  • 3. www.webstackacademy.com Relevance Discussion – The following questions are relevant to understanding what technologies are available for developing web applications and the limitations of those technologies: ● What happens if the response to an HTTP request cannot be made until a message is rteceived from a third party? Must the servlet thread be blocked indefinitely? ● Suppose dozens of clients are cooperating, for example, in a chat room. Must a request from every client be blocked waiting until one client triggers an update?
  • 4. www.webstackacademy.com Asynchronous Servlets Java EE 6 adds the option to perform request processing asynchronously. If this is done, then the servlet execution thread can be freed up to service requests from other clients, and the generation of the response may be performed in another thread, for example the thread that creates the trigger condition that allows the response to be prepared.
  • 5. www.webstackacademy.com Asynchronous Servlets Java EE 6 adds the option to perform request processing asynchronously. If this is done, then the servlet execution thread can be freed up to service requests from other clients, and the generation of the response may be performed in another thread, for example the thread that creates the trigger condition that allows the response to be prepared.
  • 6. www.webstackacademy.com Separating Request Receipt from Response Generation ● To allow for separation of request from response generation, the servlet API provides a class called AsyncContext. A servlet that wishes to hand off response generation to another thread can obtain an AsyncContext object and pass this to another thread, perhaps using a queue. ● The AsyncContext object provides access to the original HttpServletRequest and HttpServletResponse objects. ● RequestDispatcher, is achieved using one of serveral dispatch methods in the AsyncContext itself.
  • 7. www.webstackacademy.com Asynchronous Servlet Example protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { AsyncContext ac = request.startAsync(); handler.addJob(ac); }
  • 8. www.webstackacademy.com Forwarding and Filtering Asynchronous handlers are permitted to dispatch or forward their processing to other servlets or JSPs, including those that are not asynchronous (that is, they do not carry the asyncSupported=true element in the annotation). This allows a standard response page to be used as a view for both synchronous and asynchronous responses. Filters can be invoked on asynchronous invocations too. If the AsyncContext.dispatch call is used on a matching URL, the dispatcher type will by ASYNC
  • 9. www.webstackacademy.com Asynchronous Listeners The AsyncListener interface must be implemented by the listener that will be notified when these situations arise. The interface defines four listener methods: ● onComplete(AsyncEvent) ● onError(AsyncEvent) ● onTimeout(AsyncEvent) ● onStartAsync(AsyncEvent)
  • 10. www.webstackacademy.com Asynchronous JavaScript Clients(AJAX) AJAX is a technique for creating fast and dynamic web pages. AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.
  • 11. www.webstackacademy.com Combining Asynchronous Servlets With Asynchronous JavaScript ● Consider a page containing JavaScript code that makes an asynchronous request for update from the server, and a server-side implementation that uses the asynchronous servlet techniques. ● Now, if the server does not choose to respond for several minutes, the user is not inconvenienced, as the body of the page is operating normally. ● Similarly, because of the use of asynchronous servlet execution, the resource load on the server is minimized. Consequently, the response may be sent at a time convenient to the server, and the effect of server-push is achieved in an architecturally manageable way.
  • 12. Web Stack Academy (P) Ltd #83, Farah Towers, 1st floor,MG Road, Bangalore – 560001 M: +91-80-4128 9576 T: +91-98862 69112 E: [email protected]