-3

How multi-threading can be used in a real time web based application, can i get some scenarios.

I am learning Java Multi threading concept, i have worked on java web application.

But never got a chance to work on multi threading, just wanted to know for what kind of operations it can be used.

Janny
  • 127
  • 1
  • 12
  • While this topic feels like an opinion topic, I offer there are many frameworks in J2EE around ManagedExecutorServices and in JAX-RS there are async methods. Have you looked at these? – Paul Bastide Dec 14 '18 at 12:51
  • @PaulBastide I do not think it feels "opinion based", but perhaps, rather, "very broad". He is asking to make him understand some example scenarios where threading could make sense. – Pinke Helga Dec 14 '18 at 12:56
  • 1
    https://stackoverflow.com/questions/20491879/role-of-multithreading-in-web-application – hasnae Dec 14 '18 at 12:56

1 Answers1

1

For example, you are working with an order system. A user might have multiple orders, an order from eBay, another from Amazon. And you need return his/her orders by his id.

You can get his orders with a single thread:

List<Order> getOrders(String userId) {
    getEBayOrders(userId);
    getAmazonOrders(urderId);
}

if getEBayOrders takes 1 second, getAmazonOrders takes 1 second, then you need 2 seconds to return the result.

With 2 threads, you can call getEBayOrders and getAmazonOrders at the same time, then the user can get his orders in 1 second.

xingbin
  • 27,410
  • 9
  • 53
  • 103