Announcement

Collapse
No announcement yet.

HttpUrlConnection: 1. connect dauert extrem lange

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • HttpUrlConnection: 1. connect dauert extrem lange

    Hallo zusammen, ich bin hier gerade etwas am verzweifeln. Ich baue in einer Schleife ein HTTP Connect zu einem anderem Server auf und übergebe verschiedene Attribute, um mir dann das Ergebniss zu holen.<BR>
    Das 1. Connect dauert bis zu 20 sekunden... alle weiteren in der schleife ausgeführten Connects dauern nur noch den Bruchteil einer Sekunde. <BR><BR>Kennt jemand diese Phänomen?
    <BR><BR>Hier der Sourcecode:
    <PRE>
    for(i=0;i++;i<5) {
    getResponseFromURL("http://localhost:8888/xmlEvaluate", i, System.currentTimeMillies();
    }

    ....

    public String getResponseFromURL(String url, String dvbid, String lastdate) {
    long start = System.currentTimeMillis();
    long tmp = System.currentTimeMillis();
    int char_data = 0;
    StringBuffer data = new StringBuffer();
    try {
    data.append("Zeitpunkt der Meldung ");
    URL connection = new URL(url);
    tmp = System.currentTimeMillis();
    System.out.println("----> c1 "+(tmp - start ));

    huc = (HttpURLConnection)connection.openConnection();
    huc.setDefaultUseCaches( true );
    huc.setUseCaches( true );
    start = System.currentTimeMillis();
    System.out.println("----> c2 "+(start - tmp ));

    huc.setRequestProperty("dvbid",dvbid);
    huc.setRequestProperty("lastdate",lastdate);
    huc.setRequestMethod("GET");
    tmp = System.currentTimeMillis();
    System.out.println("----> c3 "+(tmp - start ));

    huc.connect();
    start = System.currentTimeMillis();
    System.out.println("----> c4 "+(start - tmp));

    BufferedInputStream bis = new BufferedInputStream( huc.getInputStream() );
    while( ( char_data=bis.read() )!=-1) {
    data.append( (char)char_data );
    }
    bis.close();
    tmp = System.currentTimeMillis();
    System.out.println("----> c5 "+(tmp - start ));

    huc.disconnect();
    } catch (Exception ex) {
    ex.printStackTrace();
    data.append("unbekannt");
    }
    return data.toString();
    }
    </PRE>

    <BR>
    der Output von c1 bis c5 für den 1. und den 2. Request sieht so aus:<BR>
    1.Request <BR>
    04/07/01 10:15:49 ----> c1 0<BR>
    04/07/01 10:15:49 ----> c2 0<BR>
    04/07/01 10:15:49 ----> c3 0<BR>
    04/07/01 10:15:49 ----> c4 0<BR>
    04/07/01 10:15:49 ----> c5 20356<BR>
    2. Request<BR>
    04/07/01 10:15:49 ----> c1 0<BR>
    04/07/01 10:15:49 ----> c2 0<BR>
    04/07/01 10:15:49 ----> c3 0<BR>
    04/07/01 10:15:49 ----> c4 0<BR>
    04/07/01 10:15:49 ----> c5 90<BR>

    Viel Dank schon mal im vorraus

    Gruss Mirko
Working...
X