SlideShare a Scribd company logo
1 of 40
Download to read offline
Jetty Continuation

작성자: 이상민


문서범위 (일반)




                     ⓒ 2010 NHN CORPORATION
목차


1. Current WAS
2. Jetty Continuation
3. Jetty Continuation sample & demo

4. Servlet 3.0
1. Current WAS
(Based on Servlet spec. 2.5)
1.1 Thread Pool




     • Whenever we request, WAS always doesn’t
      make new thread.
       It uses Thread Pool.

     • It’s not easy to set suitable Thread Pool size.

     • Thread per connection
          • The traditional IO model of java associates a thread with
          every TCP/IP connection.




                                                                 4 / Jetty Continuation
1.2 Synchronous




     • Almost all web requests are handled
      synchronously.

     • Asynchronous request handling on WAS is
      not easy.




                                             5 / Jetty Continuation
1.3 AJAX polling problem




     • AJAX servers cannot deliver asynchronous
      events to the client, the AJAX client must
      poll for events on the server.
          • To avoid a busy polling loop, AJAX servers will often hold
            onto a poll request until either there is an event or a
            timeout occurs.


     • The server again needs to have one or
      more threads for every client.
        http://docs.codehaus.org/display/JETTY/Continuations




                                                                 6 / Jetty Continuation
2. Jetty Continuation




                        7 / Jetty Continuation
2.1.1 What is Jetty




      • Jetty - http://eclipse.org/jetty/



           • Jetty provides an HTTP server, HTTP client,
             and javax.servlet container.
           • Full-featured and standards-based
           • Open source and commercially usable
           • Flexible and extensible
           • Small footprint
           • Embeddable
           • Asynchronous
           • Enterprise scalable
           • Dual licensed under Apache and Eclipse
                                                           8 / Jetty Continuation
2.1.2 Asynchronous Servlet




     • Asynchronous Servlets
          • Not Asynchronous IO
               • Asynchronous Servlets are different with
                 Asynchronous IO or the use of NIO


          • Asynchronous Waiting
               • waiting for a resource to be available before
                 processing the request
               • waiting for an application event in an AJAX Comet
                 application
               • waiting for a response from a remote service
                                                                 9 / Jetty Continuation
2.1.3 Continuation




     • Continuation in Naver dictionary




                                          10 / Jetty Continuation
2.1.3 Continuation




     • Continuation in Jetty
          • A continuation is a mechanism by which a HTTP Request

            can be suspended and restarted after a timeout or an
            asynchronous event has occurred.




                                                            11 / Jetty Continuation
2.1.2 Continuation




     • Continuation
          • Process of continuation
                                      Registered with
                                      an async. service
                                        Working in
                                        other thread

                     Return thread




                     Take thread



                                            12 / Jetty Continuation
2.2.1 Thread Pool with Continuation




     • You also should use Thread Pool when you
      use Continuation

     • But you can manage WAS with a fewer
      Thread.




                                             13 / Jetty Continuation
2.2.2 Use Asynchronous call with Continuation




     • You must use “Asynchronous call” to use
      Continuation

     • One thread can run much request at a time.




                                                14 / Jetty Continuation
2.2.3 Continuation examples




     • Chat Servlet
          • http://download.eclipse.org/jetty/stable-
            7/xref/com/acme/ChatServlet.html

     • Jetty’s filter & servlet
          • QoSFilter (Quality of Service Filter)
          • DosFilter (Denial of Service Filter)
          • GzipFilter (Compress response objects)
          • ProxyServlet




                                                        15 / Jetty Continuation
2.3 Continuation sample




     • Continuation sample
          public class ContinuationServlet extends HttpServlet{
            public void service(HttpServletRequest req,
                 HttpServletResponse res) throws IOException {
              String flag=(String)req.getAttribute("CONT_FLAG");
              if(flag==null) {
                Continuation continuation
                 = ContinuationSupport.getContinuation(req);
                continuation.addContinuationListener(new AListener());
                continuation.setTimeout(5000);
                continuation.suspend();
                req.setAttribute("CONT_FLAG", "RUNNING");
                //asynchronous call
              } else {
              }                       Call resume() or complete(),
              return;                 after work is done.
            }
                                                            16 / Jetty Continuation
2.4 Continuation interface




      • Continuation interface
           • Package : org.eclipse.jetty.continuation
           • Methods :
                • setTimeout(long)
                • addContinuationListener(ContinuationListener)
                • suspend(), suspend(ServletResponse)
                • resume()
                • complete()
                …



                                                          17 / Jetty Continuation
2.4 Continuation interface




      • Continuation interface
           • Get instance of Continuation

           Continuation continuation=
                 ContinuationSupport.getContinuation(request);




                                                        18 / Jetty Continuation
2.5.1 Continuation.setTimeout (long)




     • setTimeout(long timeoutMS) method
          • Set the continuation timeout.
          • You can set timeout in millisecond(1/1000 second) unit.
          • If timeoutMS is <=0, the continuation will never expire.
            (Don’t do that - -)


          Sample code
          //set timeout 5 seconds
          continuation.setTimeout(5000);



                                                                 19 / Jetty Continuation
2.5.2.1 Continuation. addContinuationListener(ContinuationListener )




      • addContinuationListener(ContinuationListener)
       method
          • Add a ContinuationListener
          • You can handle continuation result by ContinuationListener


          Sample code
          //Make listener class
          SampleListener listener=new SampleListener();
          //Add listener to continuation object
          continuation.addContinuationListener(listener);


                                                                       20 / Jetty Continuation
2.5.2.2 How can I make ContinuationListener?




     • Just implements ContinuationListener interface
       with two methods
          Sample code

          import org.eclipse.jetty.continuation.Continuation;
          import org.eclipse.jetty.continuation.ContinuationListener;


          public class SampleListener   implements ContinuationListener{
            public SampleListener() {
            }                                        When Continuation is completed
              public void onComplete(Continuation continuation)                             {
              }


              public void onTimeout(Continuation continuation)                            {
              }

          }                                            When Continuation is timeout
                                                                            21 / Jetty Continuation
2.5.3 Continuation.suspend()




     • suspend() & suspend(ServletResponse)
      method
          • Suspend the processing of the request and
            associated ServletResponse.

          • After this method has been called, the lifecycle of the
            request will be extended beyond the return to the container
            from
               • Servlet.service(ServletRequest, ServletResponse)
               • Filter.doFilter(ServletRequest, ServletResponse,
                 FilterChain) calls.




                                                               22 / Jetty Continuation
2.5.3 Continuation.suspend()




     • suspend() & suspend(ServletResponse)
      method
          • The thread is freed for other tasks and the request is held
            until
              • a call to resume().
              • a call to complete().
              • the timeout expires.

          Sample code

          continuation.suspend();

          or

          continuation.suspend(response);
                                                                 23 / Jetty Continuation
2.5.4 Continuation.resume()




     • resume() method
          • Resume a suspended request.
          • The request is redispatched to the normal filter chain and
            servlet processing with isInitial() false.
          • Typically resume() is used after a call to suspend() with no
            arguments.




                                                                  24 / Jetty Continuation
2.5.5 Continuation.complete()




     • complete() method
          • Complete a suspended request.
          • The associated response object committed and flushed.
            The request is not redispatched.
          • Typically complete() is used after a call
            to suspend(ServletResponse) with a possibly wrapped
            response.




                                                             25 / Jetty Continuation
2.5.5 resume() vs complete()




      • compare resume() vs complete() methods
                               resume()          complete()

         redispatch               O                   X

         suspend type          suspend()   suspend(ServletResponse)

         wrap response            X                   O




                                                              26 / Jetty Continuation
2.6 Asynchronous on Java




     • Use java.lang.Thread
          • Easy to use
          • But making new thread every time is not good in
            performance

     • Use java.util.concurrent.ExecutorService
          • Not easy to use at first time.
          • But it reuse threads and manages thread pool.




                                                              27 / Jetty Continuation
2.6 Asynchronous on Java




     • Thread sample
     package com.cont.sample.async;

     public class ThreadSample extends Thread {
       public static void main(String args[]) {
         ThreadSample sample=new ThreadSample();
         System.out.println("Before start sample.");   Before start sample.
         sample.start();                               After start sample.
         System.out.println("After start sample.");    Run method called
       }
       public void run() {
         System.out.println("Run method called");
       }
     }




                                                                  28 / Jetty Continuation
2.6 Asynchronous on Java




     • Executor sample
     package com.cont.sample.async.executor;
     public class SampleReceiver {
       public void receiveResult(Object obj) {
         System.out.println("Received result is "+obj);
       }
     }

     package com.cont.sample.async.executor;
     import java.util.concurrent.Callable;
     public class SampleCallable implements Callable<Object>{
       private SampleReceiver receiver;
       public SampleCallable(SampleReceiver receiver) {
         this.receiver=receiver;
       }
       public Object call() throws Exception {
         System.out.println("SampleCallable is called");
         receiver.receiveResult("OK");
         return null;
       }
     }

                                                                29 / Jetty Continuation
2.6 Asynchronous on Java




     • Executor sample – execute
     package com.cont.sample.async.executor;
     import java.util.concurrent.ExecutorService;
     import java.util.concurrent.Executors;
     public class ExecutorMain {
       public static void main(String[] args) {
         ExecutorService service=
              Executors.newCachedThreadPool();
                                                    Before submit
                                                    After submit
             SampleReceiver receiver=
                                                    SampleCallable is called
                  new SampleReceiver();
                                                    Received result is OK
             SampleCallable callable=
                  new SampleCallable(receiver);
             System.out.println("Before submit");
             service.submit(callable);
             System.out.println("After submit");
         }
     }




                                                                 30 / Jetty Continuation
3. Jetty Continuation sample & demo




                              31 / Jetty Continuation
3.1 Common Servlet




     • Common Servlet Sample
     • Continuation timeout sample
     • Continuation resume() sample
     • Continuation complete() sample




                                        32 / Jetty Continuation
4. Servlet 3.0




                 33 / Jetty Continuation
4.1 Servlet 3.0




      • Final release of Servlet 3.0 was announced
       at 10 Dec, 2009.

      • JSR(Java Specification Request) – 315
                  http://jcp.org/en/jsr/detail?id=315


      • Glassfish 3 is based on Servlet 3.0




                                                        34 / Jetty Continuation
4.2 Servlet 3.0 new features




      • Asynchronous Servlets and comet support.

      • Web framework pluggability.

      • Use Annotations to define web.xml setting
       easier
           • @WebServlet, @WebFilter, @WebInitParam, @WebListner,
             @MultipartConfig


      • Modularization of web.xml
           • Use web-fragment.xml file

        http://www.jsptube.com/servlet-tutorials/servlet3/new-features.html
                                                                    35 / Jetty Continuation
4.3 AsyncContext




     • AsyncContext interface
         • Package : javax.servlet
         • Class representing the execution context for an
           asynchronous operation that was initiated on a
           ServletRequest.
         • Methods :
              • setTimeout(long)
              • addListener(AsyncListener)
              • complete()
              …

                                                             36 / Jetty Continuation
4.4 ServletRequest




     • ServletRequest interface
          • Package : javax.servlet
          • Added Methods :
               • startAsync()
               • startAsync(ServletRequest , ServletResponse )
               …




                                                         37 / Jetty Continuation
5. Conclusion




                38 / Jetty Continuation
Jetty Continuation



                     One

                     Multi
                             39 / Jetty Continuation
Thank you.

More Related Content

What's hot

WebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkWebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkFabio Tiriticco
 
Real-Time with Flowdock
Real-Time with FlowdockReal-Time with Flowdock
Real-Time with FlowdockFlowdock
 
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)Peter Lubbers
 
HTML5 WebSocket Introduction
HTML5 WebSocket IntroductionHTML5 WebSocket Introduction
HTML5 WebSocket IntroductionMarcelo Jabali
 
Introduction to WebSockets
Introduction to WebSocketsIntroduction to WebSockets
Introduction to WebSocketsGunnar Hillert
 
Pushing the web — WebSockets
Pushing the web — WebSocketsPushing the web — WebSockets
Pushing the web — WebSocketsRoland M
 
Building Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using WebsocketsBuilding Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using WebsocketsNaresh Chintalcheru
 
HTTP/2 and Java: Current Status
HTTP/2 and Java: Current StatusHTTP/2 and Java: Current Status
HTTP/2 and Java: Current StatusSimone Bordet
 
WebRTC + Socket.io: building a skype-like video chat with native javascript
WebRTC + Socket.io: building a skype-like video chat with native javascriptWebRTC + Socket.io: building a skype-like video chat with native javascript
WebRTC + Socket.io: building a skype-like video chat with native javascriptMichele Di Salvatore
 
wa-cometjava-pdf
wa-cometjava-pdfwa-cometjava-pdf
wa-cometjava-pdfHiroshi Ono
 
HTTP/2 Comes to Java - What Servlet 4.0 Means to You
HTTP/2 Comes to Java - What Servlet 4.0 Means to YouHTTP/2 Comes to Java - What Servlet 4.0 Means to You
HTTP/2 Comes to Java - What Servlet 4.0 Means to YouDavid Delabassee
 
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java DevelopersWebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java DevelopersViktor Gamov
 
Java EE 8: What Servlet 4.0 and HTTP/2 mean to you
Java EE 8: What Servlet 4.0 and HTTP/2 mean to youJava EE 8: What Servlet 4.0 and HTTP/2 mean to you
Java EE 8: What Servlet 4.0 and HTTP/2 mean to youAlex Theedom
 
Websockets at tossug
Websockets at tossugWebsockets at tossug
Websockets at tossugclkao
 

What's hot (20)

WebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkWebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! Framework
 
Real-Time with Flowdock
Real-Time with FlowdockReal-Time with Flowdock
Real-Time with Flowdock
 
Php push notifications
Php push notificationsPhp push notifications
Php push notifications
 
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)
 
The HTML5 WebSocket API
The HTML5 WebSocket APIThe HTML5 WebSocket API
The HTML5 WebSocket API
 
HTML5 WebSocket Introduction
HTML5 WebSocket IntroductionHTML5 WebSocket Introduction
HTML5 WebSocket Introduction
 
HTTP/2 Comes to Java
HTTP/2 Comes to JavaHTTP/2 Comes to Java
HTTP/2 Comes to Java
 
Introduction to WebSockets
Introduction to WebSocketsIntroduction to WebSockets
Introduction to WebSockets
 
Pushing the web — WebSockets
Pushing the web — WebSocketsPushing the web — WebSockets
Pushing the web — WebSockets
 
Building Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using WebsocketsBuilding Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using Websockets
 
HTTP/2 and Java: Current Status
HTTP/2 and Java: Current StatusHTTP/2 and Java: Current Status
HTTP/2 and Java: Current Status
 
WebRTC + Socket.io: building a skype-like video chat with native javascript
WebRTC + Socket.io: building a skype-like video chat with native javascriptWebRTC + Socket.io: building a skype-like video chat with native javascript
WebRTC + Socket.io: building a skype-like video chat with native javascript
 
Cometdの紹介
Cometdの紹介Cometdの紹介
Cometdの紹介
 
wa-cometjava-pdf
wa-cometjava-pdfwa-cometjava-pdf
wa-cometjava-pdf
 
HTTP/2 Comes to Java - What Servlet 4.0 Means to You
HTTP/2 Comes to Java - What Servlet 4.0 Means to YouHTTP/2 Comes to Java - What Servlet 4.0 Means to You
HTTP/2 Comes to Java - What Servlet 4.0 Means to You
 
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java DevelopersWebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
 
HTML5 WebSockets
HTML5 WebSocketsHTML5 WebSockets
HTML5 WebSockets
 
Java EE 8: What Servlet 4.0 and HTTP/2 mean to you
Java EE 8: What Servlet 4.0 and HTTP/2 mean to youJava EE 8: What Servlet 4.0 and HTTP/2 mean to you
Java EE 8: What Servlet 4.0 and HTTP/2 mean to you
 
WebSocket protocol
WebSocket protocolWebSocket protocol
WebSocket protocol
 
Websockets at tossug
Websockets at tossugWebsockets at tossug
Websockets at tossug
 

Similar to Jetty Continuation - 이상민 (20)

Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
 
Lightweight Java EE with MicroProfile
Lightweight Java EE with MicroProfileLightweight Java EE with MicroProfile
Lightweight Java EE with MicroProfile
 
Adv java unit 4 M.Sc CS.pdf
Adv java unit 4 M.Sc CS.pdfAdv java unit 4 M.Sc CS.pdf
Adv java unit 4 M.Sc CS.pdf
 
IP UNIT III PPT.pptx
 IP UNIT III PPT.pptx IP UNIT III PPT.pptx
IP UNIT III PPT.pptx
 
ajava unit 1.pptx
ajava unit 1.pptxajava unit 1.pptx
ajava unit 1.pptx
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
 
servlet_lifecycle.pdf
servlet_lifecycle.pdfservlet_lifecycle.pdf
servlet_lifecycle.pdf
 
Servlets
ServletsServlets
Servlets
 
Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSP
 
Introduction tomcat7 servlet3
Introduction tomcat7 servlet3Introduction tomcat7 servlet3
Introduction tomcat7 servlet3
 
J2ee servlet
J2ee servletJ2ee servlet
J2ee servlet
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Servlets
ServletsServlets
Servlets
 
Advanced java+JDBC+Servlet
Advanced java+JDBC+ServletAdvanced java+JDBC+Servlet
Advanced java+JDBC+Servlet
 
Java ppt
Java pptJava ppt
Java ppt
 
Java Servlets.pdf
Java Servlets.pdfJava Servlets.pdf
Java Servlets.pdf
 
Servlet
Servlet Servlet
Servlet
 
Introduction of failsafe
Introduction of failsafeIntroduction of failsafe
Introduction of failsafe
 
Quick Introduction to Kotlin Coroutine for Android Dev
Quick Introduction to Kotlin Coroutine for Android DevQuick Introduction to Kotlin Coroutine for Android Dev
Quick Introduction to Kotlin Coroutine for Android Dev
 

More from JavaCommunity.Org

안드로이드와 이통사 확장 API
안드로이드와 이통사 확장 API안드로이드와 이통사 확장 API
안드로이드와 이통사 확장 APIJavaCommunity.Org
 
안드로이드 플랫폼기반의 푸시서버 아키텍처
안드로이드 플랫폼기반의 푸시서버 아키텍처안드로이드 플랫폼기반의 푸시서버 아키텍처
안드로이드 플랫폼기반의 푸시서버 아키텍처JavaCommunity.Org
 
이클립스와 안드로이드
이클립스와 안드로이드이클립스와 안드로이드
이클립스와 안드로이드JavaCommunity.Org
 
결합도 관점에서 본 VO 문제점
결합도 관점에서 본 VO 문제점결합도 관점에서 본 VO 문제점
결합도 관점에서 본 VO 문제점JavaCommunity.Org
 
E-Gov 기반 Mobile Web Friendly 개발
E-Gov 기반 Mobile Web Friendly 개발E-Gov 기반 Mobile Web Friendly 개발
E-Gov 기반 Mobile Web Friendly 개발JavaCommunity.Org
 

More from JavaCommunity.Org (7)

안드로이드와 이통사 확장 API
안드로이드와 이통사 확장 API안드로이드와 이통사 확장 API
안드로이드와 이통사 확장 API
 
안드로이드 플랫폼기반의 푸시서버 아키텍처
안드로이드 플랫폼기반의 푸시서버 아키텍처안드로이드 플랫폼기반의 푸시서버 아키텍처
안드로이드 플랫폼기반의 푸시서버 아키텍처
 
이클립스와 안드로이드
이클립스와 안드로이드이클립스와 안드로이드
이클립스와 안드로이드
 
결합도 관점에서 본 VO 문제점
결합도 관점에서 본 VO 문제점결합도 관점에서 본 VO 문제점
결합도 관점에서 본 VO 문제점
 
E-Gov 기반 Mobile Web Friendly 개발
E-Gov 기반 Mobile Web Friendly 개발E-Gov 기반 Mobile Web Friendly 개발
E-Gov 기반 Mobile Web Friendly 개발
 
스프링 3.0 & RESTful
스프링 3.0 & RESTful스프링 3.0 & RESTful
스프링 3.0 & RESTful
 
RESTful Java
RESTful JavaRESTful Java
RESTful Java
 

Recently uploaded

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Jetty Continuation - 이상민

  • 1. Jetty Continuation 작성자: 이상민 문서범위 (일반) ⓒ 2010 NHN CORPORATION
  • 2. 목차 1. Current WAS 2. Jetty Continuation 3. Jetty Continuation sample & demo 4. Servlet 3.0
  • 3. 1. Current WAS (Based on Servlet spec. 2.5)
  • 4. 1.1 Thread Pool • Whenever we request, WAS always doesn’t make new thread.  It uses Thread Pool. • It’s not easy to set suitable Thread Pool size. • Thread per connection • The traditional IO model of java associates a thread with every TCP/IP connection. 4 / Jetty Continuation
  • 5. 1.2 Synchronous • Almost all web requests are handled synchronously. • Asynchronous request handling on WAS is not easy. 5 / Jetty Continuation
  • 6. 1.3 AJAX polling problem • AJAX servers cannot deliver asynchronous events to the client, the AJAX client must poll for events on the server. • To avoid a busy polling loop, AJAX servers will often hold onto a poll request until either there is an event or a timeout occurs. • The server again needs to have one or more threads for every client. http://docs.codehaus.org/display/JETTY/Continuations 6 / Jetty Continuation
  • 7. 2. Jetty Continuation 7 / Jetty Continuation
  • 8. 2.1.1 What is Jetty • Jetty - http://eclipse.org/jetty/ • Jetty provides an HTTP server, HTTP client, and javax.servlet container. • Full-featured and standards-based • Open source and commercially usable • Flexible and extensible • Small footprint • Embeddable • Asynchronous • Enterprise scalable • Dual licensed under Apache and Eclipse 8 / Jetty Continuation
  • 9. 2.1.2 Asynchronous Servlet • Asynchronous Servlets • Not Asynchronous IO • Asynchronous Servlets are different with Asynchronous IO or the use of NIO • Asynchronous Waiting • waiting for a resource to be available before processing the request • waiting for an application event in an AJAX Comet application • waiting for a response from a remote service 9 / Jetty Continuation
  • 10. 2.1.3 Continuation • Continuation in Naver dictionary 10 / Jetty Continuation
  • 11. 2.1.3 Continuation • Continuation in Jetty • A continuation is a mechanism by which a HTTP Request can be suspended and restarted after a timeout or an asynchronous event has occurred. 11 / Jetty Continuation
  • 12. 2.1.2 Continuation • Continuation • Process of continuation Registered with an async. service Working in other thread Return thread Take thread 12 / Jetty Continuation
  • 13. 2.2.1 Thread Pool with Continuation • You also should use Thread Pool when you use Continuation • But you can manage WAS with a fewer Thread. 13 / Jetty Continuation
  • 14. 2.2.2 Use Asynchronous call with Continuation • You must use “Asynchronous call” to use Continuation • One thread can run much request at a time. 14 / Jetty Continuation
  • 15. 2.2.3 Continuation examples • Chat Servlet • http://download.eclipse.org/jetty/stable- 7/xref/com/acme/ChatServlet.html • Jetty’s filter & servlet • QoSFilter (Quality of Service Filter) • DosFilter (Denial of Service Filter) • GzipFilter (Compress response objects) • ProxyServlet 15 / Jetty Continuation
  • 16. 2.3 Continuation sample • Continuation sample public class ContinuationServlet extends HttpServlet{ public void service(HttpServletRequest req, HttpServletResponse res) throws IOException { String flag=(String)req.getAttribute("CONT_FLAG"); if(flag==null) { Continuation continuation = ContinuationSupport.getContinuation(req); continuation.addContinuationListener(new AListener()); continuation.setTimeout(5000); continuation.suspend(); req.setAttribute("CONT_FLAG", "RUNNING"); //asynchronous call } else { } Call resume() or complete(), return; after work is done. } 16 / Jetty Continuation
  • 17. 2.4 Continuation interface • Continuation interface • Package : org.eclipse.jetty.continuation • Methods : • setTimeout(long) • addContinuationListener(ContinuationListener) • suspend(), suspend(ServletResponse) • resume() • complete() … 17 / Jetty Continuation
  • 18. 2.4 Continuation interface • Continuation interface • Get instance of Continuation Continuation continuation= ContinuationSupport.getContinuation(request); 18 / Jetty Continuation
  • 19. 2.5.1 Continuation.setTimeout (long) • setTimeout(long timeoutMS) method • Set the continuation timeout. • You can set timeout in millisecond(1/1000 second) unit. • If timeoutMS is <=0, the continuation will never expire. (Don’t do that - -) Sample code //set timeout 5 seconds continuation.setTimeout(5000); 19 / Jetty Continuation
  • 20. 2.5.2.1 Continuation. addContinuationListener(ContinuationListener ) • addContinuationListener(ContinuationListener) method • Add a ContinuationListener • You can handle continuation result by ContinuationListener Sample code //Make listener class SampleListener listener=new SampleListener(); //Add listener to continuation object continuation.addContinuationListener(listener); 20 / Jetty Continuation
  • 21. 2.5.2.2 How can I make ContinuationListener? • Just implements ContinuationListener interface with two methods Sample code import org.eclipse.jetty.continuation.Continuation; import org.eclipse.jetty.continuation.ContinuationListener; public class SampleListener implements ContinuationListener{ public SampleListener() { } When Continuation is completed public void onComplete(Continuation continuation) { } public void onTimeout(Continuation continuation) { } } When Continuation is timeout 21 / Jetty Continuation
  • 22. 2.5.3 Continuation.suspend() • suspend() & suspend(ServletResponse) method • Suspend the processing of the request and associated ServletResponse. • After this method has been called, the lifecycle of the request will be extended beyond the return to the container from • Servlet.service(ServletRequest, ServletResponse) • Filter.doFilter(ServletRequest, ServletResponse, FilterChain) calls. 22 / Jetty Continuation
  • 23. 2.5.3 Continuation.suspend() • suspend() & suspend(ServletResponse) method • The thread is freed for other tasks and the request is held until • a call to resume(). • a call to complete(). • the timeout expires. Sample code continuation.suspend(); or continuation.suspend(response); 23 / Jetty Continuation
  • 24. 2.5.4 Continuation.resume() • resume() method • Resume a suspended request. • The request is redispatched to the normal filter chain and servlet processing with isInitial() false. • Typically resume() is used after a call to suspend() with no arguments. 24 / Jetty Continuation
  • 25. 2.5.5 Continuation.complete() • complete() method • Complete a suspended request. • The associated response object committed and flushed. The request is not redispatched. • Typically complete() is used after a call to suspend(ServletResponse) with a possibly wrapped response. 25 / Jetty Continuation
  • 26. 2.5.5 resume() vs complete() • compare resume() vs complete() methods resume() complete() redispatch O X suspend type suspend() suspend(ServletResponse) wrap response X O 26 / Jetty Continuation
  • 27. 2.6 Asynchronous on Java • Use java.lang.Thread • Easy to use • But making new thread every time is not good in performance • Use java.util.concurrent.ExecutorService • Not easy to use at first time. • But it reuse threads and manages thread pool. 27 / Jetty Continuation
  • 28. 2.6 Asynchronous on Java • Thread sample package com.cont.sample.async; public class ThreadSample extends Thread { public static void main(String args[]) { ThreadSample sample=new ThreadSample(); System.out.println("Before start sample."); Before start sample. sample.start(); After start sample. System.out.println("After start sample."); Run method called } public void run() { System.out.println("Run method called"); } } 28 / Jetty Continuation
  • 29. 2.6 Asynchronous on Java • Executor sample package com.cont.sample.async.executor; public class SampleReceiver { public void receiveResult(Object obj) { System.out.println("Received result is "+obj); } } package com.cont.sample.async.executor; import java.util.concurrent.Callable; public class SampleCallable implements Callable<Object>{ private SampleReceiver receiver; public SampleCallable(SampleReceiver receiver) { this.receiver=receiver; } public Object call() throws Exception { System.out.println("SampleCallable is called"); receiver.receiveResult("OK"); return null; } } 29 / Jetty Continuation
  • 30. 2.6 Asynchronous on Java • Executor sample – execute package com.cont.sample.async.executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class ExecutorMain { public static void main(String[] args) { ExecutorService service= Executors.newCachedThreadPool(); Before submit After submit SampleReceiver receiver= SampleCallable is called new SampleReceiver(); Received result is OK SampleCallable callable= new SampleCallable(receiver); System.out.println("Before submit"); service.submit(callable); System.out.println("After submit"); } } 30 / Jetty Continuation
  • 31. 3. Jetty Continuation sample & demo 31 / Jetty Continuation
  • 32. 3.1 Common Servlet • Common Servlet Sample • Continuation timeout sample • Continuation resume() sample • Continuation complete() sample 32 / Jetty Continuation
  • 33. 4. Servlet 3.0 33 / Jetty Continuation
  • 34. 4.1 Servlet 3.0 • Final release of Servlet 3.0 was announced at 10 Dec, 2009. • JSR(Java Specification Request) – 315 http://jcp.org/en/jsr/detail?id=315 • Glassfish 3 is based on Servlet 3.0 34 / Jetty Continuation
  • 35. 4.2 Servlet 3.0 new features • Asynchronous Servlets and comet support. • Web framework pluggability. • Use Annotations to define web.xml setting easier • @WebServlet, @WebFilter, @WebInitParam, @WebListner, @MultipartConfig • Modularization of web.xml • Use web-fragment.xml file http://www.jsptube.com/servlet-tutorials/servlet3/new-features.html 35 / Jetty Continuation
  • 36. 4.3 AsyncContext • AsyncContext interface • Package : javax.servlet • Class representing the execution context for an asynchronous operation that was initiated on a ServletRequest. • Methods : • setTimeout(long) • addListener(AsyncListener) • complete() … 36 / Jetty Continuation
  • 37. 4.4 ServletRequest • ServletRequest interface • Package : javax.servlet • Added Methods : • startAsync() • startAsync(ServletRequest , ServletResponse ) … 37 / Jetty Continuation
  • 38. 5. Conclusion 38 / Jetty Continuation
  • 39. Jetty Continuation One Multi 39 / Jetty Continuation