File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes response time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "response time" Watch "response time" New topic
Author

response time

manu chaox
Ranch Hand

Joined: Apr 10, 2006
Posts: 110
Hi,

I'd like to create a function, which will return the time(ms) corresponding response time of a web server.
I'd like to send request GET(http) on the server and than count response time(end_time - start_time).

something like:
int getResponseTime(String url,String get)
url ... page where GET is sending GET
get ... GET method of http

Could you help me please
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Look into the URL and HttpURLConnection classes. If they don't makes sense on their own, see the Sun Networking Tutorial. The 2nd lesson covers this: Your Java programs can use URLs to connect to and retrieve information over a network which sounds just about right.

Let us know if you get stuck, or what you make if you don't!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
manu chaox
Ranch Hand

Joined: Apr 10, 2006
Posts: 110
Could it be in this way?




I would like to find out response time at higher number of requests.
I would like to solve this by more threads.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
At a quick read, that looks like a good start. Do you want to actually read the results back? That would make your time include the full data transmission. And you may have to beef it up over time as you find problem sites.

You could encapsulate this in a little class and run several of them with a thread pool. At some number of threads your network connection or your program will become the bottleneck just because you're doing too much. If you ran a thousand at once they might all appear to have 60 second response time. I have a downloader that seems to run best at three or four threads, but I haven't really measured it and your mileage may vary.

Are you comfortable with the Executor in Java5 and later? You can use a fixed size pool to control the number of threads, put all your sites in queue and wait for them to finish. Join us in the Threads forum if you have any trouble.
[ June 22, 2007: Message edited by: Stan James ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: response time
 
Similar Threads
modifying URL query string
Connecting Multiple Oracle Databases with one Application
How do I close a bound socket?
How Can Build A Connetion Between Server And Client With HTTP?
How to ping a url.