1 / 15

JSR 315 – Servlet Spec 3.0

JSR 315 – Servlet Spec 3.0. Damodar Chetty damodarchetty@gmail.com Software Engineering Solutions, Inc. www.swengsol.com. Introductions. Author, Coach, Architect Blogger at www.swengsol.com Two decades in software development Adjunct Faculty at Metro State University.

salena
Download Presentation

JSR 315 – Servlet Spec 3.0

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JSR 315 – Servlet Spec 3.0 Damodar Chettydamodarchetty@gmail.com Software Engineering Solutions, Inc.www.swengsol.com

  2. Introductions • Author, Coach, Architect • Blogger at www.swengsol.com • Two decades in software development • Adjunct Faculty at Metro State University

  3. Java 6 - What’s New? • JSR 316 - umbrella specification • Contains 28 specs. • Web Services (JAX-WS, JAX-RS, JAXB, …) • Web (Servlet 3, JSF, JSP, JSTL, EL) • Enterprise (EJB 3, JPA, JTA, …) • Misc (Annotations, …) • Introduces Pruning and Profiles JAX-RPC, JAXR, EJB 2 CMP Web Profile 1.0 : Web, EJB Lite, JPA, JTA, Annotations

  4. Servlet 3.0: What’s on our menu? • Asynchronous Servlets • Enhanced Modularity • Programmatic registration and configuration of components • Annotations • Security (won’t discuss this tonight)

  5. Annotation Processing • web.xml is optional but overrides annotations • Scans WEB-INF/classes and WEB-INF/lib/*.jar • metadata-complete attribute • Annotations for components • Servlets • Filters • Listeners • Ordering is unspecified • Demo MyFilter, HelloWorldServlet @WebServlet(name=“fooServlet”, urlPatterns={“/foo”, “/bar”} asyncSupported = false) @WebFilter(urlPatterns={“/foo”, “/bar”} servletNames={“fooServlet”}) @WebListener

  6. Programmatic Definition • Create and configureServlets, Filters, and Listeners • Useful to frameworks • DemoMyServletContextListener, MyProgrammaticFilter, MyProgrammaticServlet

  7. Pluggability • Frameworks can plug-in to your application • Configuration • Resources • Container assembles all fragments • DemojSwengsol.jar META-INF/web-fragment.xml lets frameworks augment your web.xml META-INF/resources frameworks can serve up static and dynamic resources from your application’s WEB-INF! Supports relative or absolute ordering

  8. Async Servlets – Prior to JSR315 • The Synchronous Web • HTTP Connections • One Server Thread Per Connection • Server Thread Pool Mechanism HTTP 1.0 and HTTP 1.1 differences Connector / Acceptor / Processor

  9. Async Servlets – The Problem • Thread Starvation • Threads consume resources • Blocking consumes threads • Staleness • Static snapshots into a dynamic system • Ajax improves freshness, but does not solve. • Non standard solutions • Tomcat’s Comet, WebLogic’s Future Response servlet,WebSphere’s Asynchronous Request Dispatcher

  10. Async Servlets – After JSR315 • The Asynchronous Web • Solves Thread Starvation • Solves Staleness • Solves Non Standard Solutions Processor thread delegates to async thread and returns to processing connections Client can make preemptive requests. The one true way

  11. Async Servlets – Ingredients • Thread Pool and Queue • AsyncContext • Runnable instance • Servlet/Filter chain Executor & ExecutorService Asynchronous Execution Context wraps the request and response Encapsulates the processing of the blocking request All components in the processing chain must be marked as supporting asynchronous requests

  12. Async Servlets – The Recipe • Context listener sets up an Executor • Servlets/filters that will block are marked as asyncSupported. • An async servlet: • invokes startAsync() on the request • wraps the returned AsyncContext in a Runnable, • hands the Runnable to an Executor for async processing. • returns without the response being committed. • The main thread returns to the server’s pool ready to handle the next request. • The Executor assigns an async thread to process the Runnable. • The Runnable: • uses the request and response stored in its AsyncContext • accesses request attributes/parameters as necessary. • stores the result in the request. • “completes” the response, by generating the response, or by dispatching to a server side resource. • The client, which has been waiting patiently, now displays the response.

  13. State Transition Diagram Synchronous servlet Async dispatch Async complete

  14. Async Servlets – Demo • AsyncServlet, AsyncRequestProcessor, MyAsyncListener

  15. Thank You! • damodarchetty@gmail.comdamodarchetty@softwareengineeringsolutions.com • www.swengsol.com • 651 270 8457 Contact information for training/consultation:

More Related