my appet opens many url connections and reads data from it . it is very slow is there a way to make it fast
URL url = null;
url2[q] = "http://www.url.com";
url = new URL(getCodeBase(), fileToRead);
InputStream in = url.openStream();
BufferedReader bf = new BufferedReader(new InputStreamReader(in));
strBuff1 = new StringBuffer();
while ((inputLine = bf.readLine()) != null)
can i open many connections simutaneuosly i am using a for loop to open connections
i use the code on the top with a for loop .i think what you have given is almost the same as i use can i make it faster by opening connections simultaneously to many sites not one after the other so time is saved is it possible to do that
,,, thanks in advance
vikram kamath c wrote:i think what you have given is almost the same as i use
It's not the same by a long shot.
can i make it faster by opening connections simultaneously to many sites not one after the other so time is saved
Yes that's possible, and it's what Oleg's code (but not your code) does.
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
This is correct only if the encoding of the pages read from all the external sites is the same as the platform default encoding of the machine running the applet. For example, www.coderanch.com uses UTF-8, while java.sun.com uses ISO-8859-1, so the code isn't even correct for those two sites.
can you suggest how to use Oleg's code for my program .i don't have much knowledge about threads Thank you Oleg,Thank you Ulf dittmer i have 5 methods which use run like the one i showed in the third thread .thanks .....
Oleg's code looks like a complete application to me; did you get it to run? If so, you need to refactor the URLConnectionReader class from an application to an applet (which chiefly means replacing the "main" method by suitable "init" and "start" methods).