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
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
Joined: Apr 10, 2006
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.
Joined: Jan 29, 2003
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 ]