• 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Performance Issue: HttpURLConnection

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am developing a server application, which has to query another server to get the info it needs. So, in my Servlet program, first I send request to the remote URL through HttpURLConnection.The code is like following:
String strURL = "...";
try{
URL url = new URL(strURL);
conn = (HttpURLConnection)url.openConnection();
if(conn!=null){
reader = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
while((line = reader.readLine())!=null){
//process the line
}
}

}
}catch(Exception e){
//do nothing
}finally{
if(reader!=null)
reader.close();
if(conn!=null)
conn.disconnect();
}
This approach works, but I found it is pretty slow. Most of time is spent on the statement to get the BufferedReader...
Any advice?
Thanks.
 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure this is what you are looking for:
but check this url pout:
http://developer.java.sun.com/developer/technicalArticles/InnerWorkings/JDCPerformTips/
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic