• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to send concurrent HTTP requests to a service in Java

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I'm new to Java world, So I need small help from Java geeks over here
I want to send multiple concurrent requests (say 100) to a Java web service and want to log the response back asynchronously.
I have tried searching on internet, But I was not able to find any proper answer(Maybe due to my little knowledge).
Any lead would be helpful.

Thanks in Advance for your time and inputs.


 
Greenhorn
Posts: 22
Oracle Ruby Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can make use of shell scripting to make a curl request 100 times and log back the response in a text file which might be some .text or .log file
 
GursewakSingh Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ Sibendu, Thank you so much for your help. it is really helpful.
I will try with curl.
Here, I would like to ask is there any way using Java code to achieve this?
As I was searching, I found that there is concurrent package in Java which can provide this functionality.
But I'm still searching how to achieve that.
Thanks again
 
Sibendu Dey
Greenhorn
Posts: 22
Oracle Ruby Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In java , every http request is routed through a servlet dispatcher which in turn invokes a servlet.Each http request is handled as a separate operation in its  own call stack ( by a thread).So multiple threads will be created by the container to take care of multiple requests.Having said so you do need to take care about your classes and their members being accessed concurrently by several threads with the help of synchronization mechanism.
 
Ranch Hand
Posts: 104
2
Eclipse IDE Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apache provides advanced Http java libraries to achieve more complex scenarios easily.

Details are here.

I think for your requirement, Asynch HttpClient can be better choice.


 
GursewakSingh Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Omkar, Thank for help.

I was trying to use Async HttpClient. I have gone documentation and sample example
Here is the sample code that I found, where we can add multiple requests.

final HttpGet[] requests = new HttpGet[] {
                   new HttpGet("http://www.apache.org/"),
                   new HttpGet("https://www.verisign.com/"),
                   new HttpGet("http://www.google.com/")
           };

But I want to single POST request multiple time (Say 100) concurrently.

So is there any method, which provides such capability.
Thanks
 
Omkar Shetkar
Ranch Hand
Posts: 104
2
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably you can have a look here.
AsyncHttpClient.java exposes APIs for http requests.
Needs some API exploration.
 
Saloon Keeper
Posts: 24283
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a couple of open-source stress-test apps in Java that do that. I don't remember their names offhand, but one or 2 of them are Apache products.
 
Your mother was a hamster and your father was a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic