[jcifs] Multiple Threads Causes Server Timeout
tim_wiffen at westlb.co.uk
tim_wiffen at westlb.co.uk
Thu Apr 14 14:53:00 GMT 2005
jcifs version: 1.1.9
I have some code that runs a pool of 3 threads that pick file requests off
a list and fetch them. As a unit test I am using this to copy 300 files
(total size of files 500MB) in a directory on a remote server. However
after copying about 50 files I start to get SmbExceptions but other files
are copied successfully after these errors:
jcifs.smb.SmbException: Timeout waiting for response from server:
someserver.myserver.net/123.45.67.89
at jcifs.smb.SmbTransport.send(SmbTransport.java:671)
at jcifs.smb.SmbSession.send(SmbSession.java:259)
at jcifs.smb.SmbTree.send(SmbTree.java:103)
at jcifs.smb.SmbFile.send(SmbFile.java:725)
at jcifs.smb.SmbFileInputStream.read(SmbFileInputStream.java:147)
at jcifs.smb.SmbFileInputStream.read(SmbFileInputStream.java:105)
at
com.westlb.GOScheduler.util.TestFileManagement.jcifsCopy(TestFileManagement.java:236)
at
com.westlb.GOScheduler.util.TestFileManagement.access$000(TestFileManagement.java:27)
at
com.westlb.GOScheduler.util.TestFileManagement$2CopyThread.run(TestFileManagement.java:187)
at java.lang.Thread.run(Thread.java:595)
The other exception that gets output to the console (but from somewhere in
the library, not by my code) is:
socket closed: someserver.myserver.net/123.45.67.89
java.net.SocketException: socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at
jcifs.netbios.SessionServicePacket.readn(SessionServicePacket.java:70)
at
jcifs.netbios.SessionServicePacket.readPacketType(SessionServicePacket.java:84)
at jcifs.netbios.SocketInputStream.read(SocketInputStream.java:74)
at jcifs.netbios.SocketInputStream.read(SocketInputStream.java:40)
at java.io.FilterInputStream.read(FilterInputStream.java:66)
at java.io.PushbackInputStream.read(PushbackInputStream.java:120)
at jcifs.smb.SmbTransport.run(SmbTransport.java:388)
My guess is that the connections to the server are not being closed, and
as there is no close() method in the SmbFile class there is nothing I can
do to force these collections to close. This means that the server hits
it's max connections and starts to drop some. I tried setting jcifs.smb.client.soTimeout to a lower value and this seemed to improve things a little, but perhaps
I imagined that.
Here is some test code to illustrate the problem:
public void testJCIFSThreads() {
final int THREADS = 3; //Set thread to 1 and no errors occur
try {
SmbFile smbfile = null;
smbfile = new SmbFile("smb://USERNAME:PASSWORD@SERVERPATH");
//server path to directory with 300 (0 - 22MB) files
SmbFile[] files = smbfile.listFiles();
List fetchlist = new ArrayList();
Thread[] threads = new Thread[THREADS];
for(int i = 0; i < files.length; i++) {
if(files[i].isFile())
fetchlist.add(files[i].getPath());
}
final Iterator listIter = fetchlist.iterator();
class CopyThread implements Runnable {
File file;
public void run() {
String uri = "SOME_TEXT";
File file;
try {
while (!"".equals(uri)) {
file = File.createTempFile("temp", ".tmp");
synchronized (listIter) {
if (listIter.hasNext())
uri = (String) listIter.next();
else
uri = "";
}
try {
if (!"".equals(uri))
if(jcifsCopy(uri, file))
file.delete();
} catch (CannotReadFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
for(int i = 0; i < THREADS; i++ ) {
threads[i] = new Thread(new CopyThread(), "Worker" + i);
threads[i].start();
}
for(int i = 0; i < THREADS; i++ ) {
threads[i].join();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (SmbException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private boolean jcifsCopy(String uri, File destination) throws
CannotReadFileException, IOException {
SmbFileInputStream is = null;
FileOutputStream os = null;
SmbFile smbfile = null;
try {
smbfile = new SmbFile(uri);
LOGGER.info("Fetching " + uri);
if (!smbfile.isFile())
return false;
if (!smbfile.canRead())
throw new CannotReadFileException();
is = new SmbFileInputStream(smbfile);
os = new FileOutputStream(destination);
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = is.read(buf)) > 0) {
os.write(buf, 0, bytesRead);
}
return true;
} finally {
os.close();
is.close();
}
}
Regards
Tim Wiffen
This message is confidential and may be privileged. It is
intended solely for the named addressee. If you are not the
intended recipient please inform us. Any unauthorised
dissemination, distribution or copying hereof is prohibited.
As we cannot guarantee the genuineness or completeness of
the information contained in this message, the statements
set forth above are not legally binding. In connection
therewith, we also refer to the governing regulations of
WestLB concerning signatory authority published in the
standard bank signature lists with regard to the legally
binding effect of statements made with the intent to
obligate WestLB.
Diese Nachricht ist vertraulich. Sie ist ausschliesslich fuer
den im Adressfeld ausgewiesenen Adressaten bestimmt.
Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten
wir um eine kurze Nachricht. Jede unbefugte Weiterleitung
oder Fertigung einer Kopie ist unzulaessig. Da wir nicht die
Echtheit oder Vollstaendigkeit der in dieser Nachricht
enthaltenen Informationen garantieren koennen, schliessen wir
die rechtliche Verbindlichkeit der vorstehenden Erklaerungen
und Aeusserungen aus. Wir verweisen in diesem Zusammenhang
auch auf die fuer die Bank geltenden Regelungen ueber die
Verbindlichkeit von Willenserklaerungen mit verpflichtendem
Inhalt, die in den bankueblichen Unterschriftenverzeichnissen
bekannt gemacht werden.
-------------- next part --------------
HTML attachment scrubbed and removed
More information about the jcifs
mailing list