Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Servlets
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Servlets
Please help me to understand this snipped of code ?
gurpeet singh
Ranch Hand
Posts: 924
1
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
please refer the URL at
http://www.javaworld.com/javaworld/jw-02-2009/jw-02-servlet3.html?page=2
following is code listing from above mentioned URL
@WebServlet(name="myServlet", urlPatterns={"/slowprocess"}, asyncSupported=true) public class MyServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) { AsyncContext aCtx = request.startAsync(request, response); ServletContext appScope = request.getServletContext(); ((Queue<AsyncContext>)appScope.getAttribute("slowWebServiceJobQueue")).add(aCtx); } } @WebServletContextListener public class SlowWebService implements ServletContextListener { public void contextInitialized(ServletContextEvent sce) { Queue<AsyncContext> jobQueue = new ConcurrentLinkedQueue<AsyncContext>(); sce.getServletContext().setAttribute("slowWebServiceJobQueue", jobQueue); // pool size matching Web services capacity Executor executor = Executors.newFixedThreadPool(10); while(true) { if(!jobQueue.isEmpty()) { final AsyncContext aCtx = jobQueue.poll(); executor.execute(new Runnable(){ public void run() { ServletRequest request = aCtx.getRequest(); // get parameteres // invoke a Web service endpoint // set results aCtx.forward("/result.jsp"); } }); } } } public void contextDestroyed(ServletContextEvent sce) { } }
can somebody just explain this code. not be line by line just the important parts. i shall be very grateful
Regards
Bear Bibeault
Sheriff
Posts: 67746
173
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
What is it that you don't understand from the article from which this code comes from? You surely don't expect anyone to start from scratch when that article already exists?
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
What are you doing? You are supposed to be reading this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Asynchronous Filter post processing
Synchronizing without blocking in a servlet filter
AsyncContext timeout
Thread wait()
Servlet 3.0 Async and Threads
More...