Your SlideShare is downloading. ×
Async servlets
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Async servlets

644
views

Published on

Published in: Technology, Education

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
644
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
14
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Async Servlets & NIO Connectors
  • 2. Agenda • Servlets • Connectors • Async Servlets • Ausblick 07.08.2013 2
  • 3. Servlets 07.08.2013 3
  • 4. Aufbau 07.08.2013 4
  • 5. Threading Model 07.08.2013 5 Thread Thread Thread Thread Thread Threadpool Web Listener Request Socket create Response Connector Servlet Servlet ServletServlet.do…(Request, Respone) Thread
  • 6. Connectors BIO/NIO/APR 07.08.2013 6
  • 7. Tomcat Connectors Java Blocking Connector Java Non Blocking Connector APR/native Connector BIO NIO APR Classname Http11Protocol Http11NioProtocol Http11AprProtocol Tomcat Version 3.x onwards 6.x onwards 5.5.x onwards Support Polling NO YES YES Polling Size N/A maxConnections maxConnections Read HTTP Request Blocking Non Blocking Blocking Read HTTP Body Blocking Sim Blocking Blocking Write HTTP Response Blocking Sim Blocking Blocking Wait for next Request Blocking Non Blocking Non Blocking SSL Support Java SSL Java SSL OpenSSL SSL Handshake Blocking Non blocking Blocking Max Connections maxConnections maxConnections maxConnections 07.08.2013 7 Quelle: http://tomcat.apache.org/tomcat-7.0-doc/config/http.html#Connector_Comparison Sim Blocking = „simulated blocking“
  • 8. Fazit • Während des Aufrufs der Methode do[POST|GET|…] (…) wird immer eine Thread pro Request gebunden • Was aber, wenn in der do-Methode selbst gewartet wird? • Der Thread wird nicht für den Thread Pool freigegeben! 07.08.2013 8
  • 9. Asynchronous Servlets 07.08.2013 9
  • 10. Async(hronous) Serlvet • Neu in Servlet 3.0 Spec (Tomcat 7) • Ermöglichen das Lösen der HTTP Anfrage vom Aufruf der do-Methode 07.08.2013 10
  • 11. Konfiguration • Per Annotiation @WebServlet(…, asyncSupported=true) • Web.xml Wichtig: Jeder Filter vor dem Servlet muss ebenfalls so konfiguriert sein! 07.08.2013 11 <servlet> <description>xxx</description> <servlet-name>xxx</servlet-name> <servlet-class>com.xxx.yyy</servlet-class> <async-supported>true</async-supported> </servlet>
  • 12. Verwendung @Override protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { final AsyncContext context = request.startAsync(); context.start(new Runnable() { @Override public void run() { doSomething(context); context.complete(); } } } 07.08.2013 12
  • 13. Ausblick 07.08.2013 13
  • 14. Problem • Beim Lesen der Daten aus dem InputStream wird dennoch ein Thread blockiert • Lesen ist blockiert und wartet auf Daten • Besser: Nur Aktiv werden wenn auch Daten da sind • Lösung: Servlet Spec 3.1 (Tomcat 8) – JSR 340 07.08.2013 14
  • 15. JSR 340 - Non Blocking IO • Neue Methoden in ServletInputStream Klasse: o setReadListener(ReadListener listener) o isReady():boolean o isFinished(): boolean • Neues Interface: ReadListener 07.08.2013 15 <interface> ReadListener onDataAvailable() onAllDataRead() onError(Throwable t)
  • 16. Fragen? 07.08.2013 16