HTTPClientTest の同じインスタンスを使用する 2 つのスレッドがあります。2 つのスレッドが同じ HTTPClientTest で send メソッドを呼び出します。send メソッドを呼び出すスレッドごとに異なるソケット タイムアウトを設定する方法を教えてください。send メソッド内でこのようなことを行うと、send メソッドを実行する両方のスレッドで同じソケット タイムアウトが発生します。
managerParams.setSoTimeout(60);connectionManager.setParams(managerParams);
HTTPClientTest の同じインスタンスで send メソッドを実行する複数のスレッドに対して、別のソケット タイムアウトを作成する方法を教えてください。
public class HTTPClientTest implements Runnable{
private HttpClient httpClient;
private MultiThreadedHttpConnectionManager connectionManager;
private HttpConnectionManagerParams managerParams;
private HttpClientTest()
{
connectionManager = new MultiThreadedHttpConnectionManager();
httpClient = new HttpClient(connectionManager);
}
public static synchronized HTTPClientTest getInstance()
{
if(instance == null)
instance = new HTTPClientTest();
return instance;
}
public void send(String message, String url)
{
PostMethod post = new PostMethod(url);
String reply = "";
String length = message.length() + "";
post.setRequestHeader("Content-Length", length);
try
{
System.out.println("HTTP request: " + message);
StringRequestEntity postBody = new StringRequestEntity(message, "text/xml", "UTF-8");
post.setRequestEntity(postBody);
int status = httpClient.executeMethod(post);
System.out.println("HTTP status: " + status);
reply = post.getResponseBodyAsString();
System.out.println("HTTP Post response code: " + reply);
}
catch(HttpException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
post.releaseConnection();
}
}
}