Hello,
unfortunately, you left out the part where the HttpClient instance is
created.
Did you remember to install a MultiThreadedHttpConnectionManager?
If the same client object is passed to several of the SaveAttachmentThread
instances, you need the thread-safe connection manager.
But the main problem should be that you do not call
getMethod.releaseConnection() after reading the response body.
This should best be done in a finally clause, since it is necessary
no matter whether there is a problem or not.
With your implementation and the SimpleHttpConnectionManager which is
used by default, a single download should succeed. All other downloads
then wait for the connection that is never released by the first one.
cheers,
Roland
"Koundinya \(Sudhakar Chavali\)" <[EMAIL PROTECTED]>
06.09.2004 14:25
Please respond to
"Commons HttpClient Project"
To
[EMAIL PROTECTED]
cc
Subject
URLGetMethod.executeMethod is hanging under multi threaded environment
Subject: URLGetMethod.executeMethod is hanging under multi threaded
environment
Hello Guys,
Please see the folloiwng code. I am trying to download the mails of MS
Exchange Server using
URLGetMethod.executeMethod. But when execution pointer comes to the thread
area
(URLGetMethod.executemethod),
URLGetMethod.executemethod is not coming out of it's loop. Could you
please explain what is the
problem with this code??
class SaveAttachmentThread
extends Thread
implements Runnable {
static int threadCount = 0;
String uri = "";
String strAttachmentName = "";
private org.apache.commons.httpclient.HttpClient client = null;
org.apache.commons.httpclient.methods.UrlGetMethod attachmentMethod =
null;
public SaveAttachmentThread(String uri, String strAttachmentName,
org.apache.commons.httpclient.HttpClient
client) {
this.uri = uri;
this.strAttachmentName = strAttachmentName;
this.client = client;
}
public SaveAttachmentThread(org.apache.commons.httpclient.methods.
UrlGetMethod _getMethod, String attachment)
{
attachmentMethod = _getMethod;
this.strAttachmentName = attachment;
}
public void run() {
//strAttachmentName = URLDecoder.decode(strAttachmentName);
System.err.println("Saved to " + strAttachmentName);
System.err.println("URL :" + uri);
try {
System.err.println("Saving the URL :" + strAttachmentName);
org.apache.commons.httpclient.methods.UrlGetMethod getMethod = new
org.
apache.commons.httpclient.methods.UrlGetMethod(uri);
int status = client.executeMethod(getMethod);
byte attachmentBytes[] = getMethod.getResponseBody();
FileOutputStream fout = new FileOutputStream(strAttachmentName);
fout.write(attachmentBytes);
fout.close();
fout = null;
threadCount++;
System.err.println(threadCount);
}
catch (Throwable e) {
System.err.println("Error raised while saving the URI : " +
strAttachmentName);
e.printStackTrace();
}
}
}
thanks
Sudhakar
P.S:
The Client Instance creating is some thing like this
try {
org.apache.commons.httpclient.HttpURL url = (org.apache.commons.
httpclient.HttpURL) getURL(path + "/" + user);
org.prithvi.docparser.microsoft.msexchange.apache.OwaWebdavResource
webDavResourceFile = getWebResource(
url);
//get the client session
client = webDavResourceFile.retrieveSessionInstance();
}
catch (Throwable ex) {
//set the client session instance to null;
client = null;
}
I mean for creating client instance I am using
WebDaveResource.retrieveSessionInstance()
=====
"No one can earn a million dollars honestly."- William Jennings Bryan
(1860-1925)
"Make everything as simple as possible, but not simpler."- Albert Einstein
(1879-1955)
"It is dangerous to be sincere unless you are also stupid."- George
Bernard Shaw (1856-1950)
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail
---------------------------------------------------------------------
To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]