Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Future on Servlet #scala_ks

860 views

Published on

Published in: Technology
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/qURD } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/qURD } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download doc Ebook here { https://soo.gd/qURD } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Future on Servlet #scala_ks

  1. 1. Future on Servlet Kazuhiro Sera @seratch 2015/08/01
  2. 2. Who am I •@seratch •ScalikeJDBC(2011 ∼) •Skinny Framework(2013 ∼) •Scalatra、json4s、Scalate •M3, Inc. Software Developer
  3. 3. Agenda •Why Future •Thread local things in the wild •Future has its own thread pool •Servlet API s mutability •recycling request issue in async mode •Scalatra DynamicScope issue •Skinny 2 s solution
  4. 4. Why Future
  5. 5. How to use Future •1) Creating and composing multiple Futures and then Await.result(Future), returning Servlet response synchronously •2) Running Servlets in async mode supported since Servlet 3
  6. 6. Why Future •Using Future on Servlet is not always recommended •OTOH, Future is the standard in Scala now, sometimes needed to smoothly integrate Future-based libraries •My near affair: using nulab/scala-oauth2- provider in a Servlet application
  7. 7. Thread local things in the wild
  8. 8. Threaded model •one thread for one request •A thread returns a response for a request •On the same thread for whole process •Thread pool managed by containers •JavaEE 7 has JSR-236 to show how to use concurrency
  9. 9. ThreadLocal •DynamicVariable in Scala •Sometimes have an easy time of it by using ThreadLocal if no multithreading •No need to take state around to methods •AOP friendly •Implicit state makes code simple
  10. 10. Future has its own thread pool
  11. 11. Future •Future scaladoc •Future.apply { different thread here } •Future.successful { same thread here } •Can easily create async operations that run on different threads managed by thread pool (ExecutionContext) •Too easy to access fields on the Servlet thread from Future threads
  12. 12. Servlet API s mutability
  13. 13. Servlet API is mutable •Request#setAttribute(String, AnyRef) •Implementation patterns that depend on request attributes •Objects managed by containers •Writing result value on response any time •Simply accessing them among multiple threads is so fragile
  14. 14. recycling request issue in async mode
  15. 15. JSR 340: Java Servlet 3.1 Specification https://jcp.org/en/jsr/detail?id=340
  16. 16. Bug 433321 - request.getContextPath() is null when working in async mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=433321 Jetty
  17. 17. Bug 46792 - NullPointerException in org.apache.catalina.connector https://bz.apache.org/bugzilla/show_bug.cgi?id=46792#c5 Tomcat
  18. 18. JSR 340: Java Servlet 3.1 Specification https://jcp.org/en/jsr/detail?id=340
  19. 19. recycling requests •In fact, request can be recycled before AsyncContext#complete() •Containers commonly do the recycle in order to avoid performance overhead •If I understand right, even though Servlet spec says same about response (5.7), response won t be recycled until its closure at least in cases of stateless HTTP
  20. 20. Scalatra DynamicScope issue
  21. 21. Too easy to access this value everywhere including Future threads created on this Servlet
  22. 22. request/response •ScalatraBase s request/response are thread local, too dangerous to access them from Future threads •All the DSL and extensions don t accept request as implicit parameter •In the initial state, this design is reasonable (Future didn t exist at the time, Sinatra concept)
  23. 23. Skinny 2 s solution
  24. 24. Skinny 2.0
  25. 25. skinny-engine
  26. 26. skinny-engine •Started as a Scalatra fork, much improved internal code while DSL source compatibility is kept •Many renaming/re-packaging and a few removal on traits •Passed all the Scalatra s existing tests •I d love to contribute skinny-engine s improvements to Scalatra too
  27. 27. stable request
  28. 28. stable request •Stable access to read-only data, request attributes even when request has been recycled while Future ops are still running •Validates unstable access to objects managed by containers (2.0.0.M3) •Should work at least on Jetty and Tomcat
  29. 29. No more DynamicScope
  30. 30. No more DynamicScope •Pass skinny.engine.Context as implicit parameter to all the DSL APIs •AsyncSkinnyEngineServlet/Filter accept (Context) => Any as action instead •On Scalatra compatible traits, detect fragile code by checking compilation errors: error: ambiguous implicit values
  31. 31. New async trait
  32. 32. Scalatra compatible trait
  33. 33. Oh-ki-ni! :) ( Thanks in Osaka)

×