I'm not a CS guru nor a Java expert, so please forgive me if the answer to the following question is obvious:
I've built a class that handles sending a query to an HTTP server, getting the response and returning that response to the caller.
My question is this; If I call that function once, and the response is taking a long time, and during the delay, I call it again, will the delayed first call interfere with the execution of the second call?
By popular demand...here is some source code:
package com.cambrothers.wms.module;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
public class ServerComm {
public HashMap<String, String> sendData(String endpoint, String requestParameters){
HashMap<String, String> response_data = new HashMap<String, String>();
System.out.println("GetRequest");
if (endpoint.startsWith("http://"))
{
// Send a GET request to the servlet
try
{
// Send data
String urlStr = endpoint;
if (requestParameters != null && requestParameters.length () > 0)
{
urlStr += "?" + requestParameters;
}
URL url = new URL(urlStr);
URLConnection conn = url.openConnection ();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = rd.readLine()) != null)
{
sb.append(line);
}
rd.close();
String result = sb.toString();
String[] values = result.split("&");
String[] kp = null;
for(int i =0; i < values.length ; i++){
kp = values[i].split("=");
response_data.put(kp[0], kp[1]);
}
} catch (Exception e)
{
e.printStackTrace();
}
}
return response_data;
}
}
take care