2

I'm making Android App with Jsoup. My code is as below.

String URL = “http://www.example.com/queryDFSRSS.jsp?zone=“
String zone_1 = “001”;
String zone_2 = “002”;
String zone_3 = “003”;

Document doc = Jsoup.connect(URL+zone_1).get();
. . . . 
doc = Jsoup.connect(URL+zone_2).get();
. . . . .
doc = Jsoup.connect(URL+zone_3).get();
.. . . . 

It takes long time. (about 2.4sec.. I guess, 0.8sec for each connection)

But, I think that they are same URL.. so it may be possible to get 3 zone data only 1 connection(slightly more times than 0.8 sec).

Is is possible?

Zack
  • 3,819
  • 3
  • 27
  • 48
  • Have you considered loading/storing from a job queue rather than on demand? – Zack Jul 22 '16 at 15:38
  • Thank you. But I don't understand(sorry. i'm beginner). Can you explain more? [ I'm making weather App. In my App, there are 10 pre-registered region. When App start, user select one region. Because I have no my own server, I want to get 10 region's weather data from web-site using Jsoup during Splash loading. But, it takes too long time(about 5~6sec). ] – Taejin. Mun Jul 22 '16 at 16:06

1 Answers1

1

It is not possible to add connection pooling to Jsoup unless you create a new implementation of org.jsoup.Connection.

Underneath the hood, Jsoup uses org.jsoup.helpers.HTTPConnection as the implementation of this interface.

In particular, you would need to modify how the Response class handles the java.net.HttpURLConnection object. Here is the current implementation:

HTTPConnection.Response.execute(Connection.Request req, Response previousResponse) {

    HttpURLConnection conn = createConnection(req);
    ...
    conn.connect();
    ...
    conn.disconnect();

}

https://github.com/jhy/jsoup/tree/master/src/main/java/org/jsoup/helper

Zack
  • 3,819
  • 3
  • 27
  • 48