java - JSP Servlet Multithreading Qustion -


I have a service which receives the request from the client, then the service has 5 different through HTTP request / feedback - Collected data from different servers (1 second required to answer each server) and sends data back to the customer.

The problem is that when the customer has to wait 6 seconds for the response then it is too long so 5 requests of 5 servers should be sent at the same time.

Thoughts:

  1. Multi-threading in servlets, such as in normal Java applications.
  2. One volunteerlet for each server (request), so that the Servlet 5 consisting of 1 main service number 5 "Receive data" and collect Servlets send data to the main servlet and main servlet back to the customer.

    I am scared about the problem, that a thread / servlet gets a response from another request because its same time and only one IP.

    How to solve this? Thanks!

    multithreading in servlet

    Which can put this request in asynchronous mode, and starts its AsyncContext with the original (inferred) ServletRequest and ServletResponse objects.

    It has been explained in detail, read more about it.

    asyncContext is a standard method defined to handle Servlet 3.0 specification HTTP request asynchronously < / P>


    Read more about this, that makes a thread pool that re-uses the thread of a fixed number of shared limitless operations off, at any time, most nThreads threads will have active processing functions. If all the threads are active, additional tasks are submitted, until there is no thread available, they will wait in queue.

    Please read more about this with sample code.



Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -