Answer the question
In order to leave comments, you need to log in
Can I read from a page in multiple threads??
I wondered if it is possible to make reading from a page in several threads ??
For example:
public StringBuffer getQuery(String urlToRead) {
URL url;
HttpURLConnection conn;
BufferedReader rd;
String line;
StringBuffer result = new StringBuffer();
try {
url = new URL(urlToRead);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = rd.readLine()) != null) {
result.append(line);
}
rd.close();
} catch (Exception e) {
getQuery(urlToRead);
e.printStackTrace();
}
return result;
Answer the question
In order to leave comments, you need to log in
"Is it possible to read from a page in multiple threads?" - you should think about this even before writing the code.
Suppose you have a book, and you decide to read it at the same time by some company. How would you organize it?
The first thing that comes to mind is to find a responsible "dispatcher" who will give portions of pages to each participant.
But what if the book is not divided into pages? How to share it then? It turns out that at first it is necessary for someone to read it, then share it, then distribute the parts. But why, then, read an already read book (if, of course, the goal is only in the very fact of reading)?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question