J
jmail
I have written a simple java app using the two classes at the end of
this post. This app works fine on several machines, but not on the Red
Hat linux server that I really need it to run on. On the Red Hat
machine, I get the following program output and stack traces.
//BEGIN PROGRAM OUTPUT
Starting TestURL
Starting the threads...
Thread 1: Starting
Thread 1: URL is http://www.visnat.com/entry/vnimages/workplace1.jpg
End of TestURL after starting threads...
Thread 2: Starting
Thread 2: URL is http://www.visnat.com/entry/vnimages/justthetv.gif
Thread 2: the url openstream call
failed:java.lang.NullPointerException
java.lang.NullPointerException
at
gnu.java.net.LineInputStream.LineInputStream(java.io.InputStream,
java.lang.String) (/usr/lib/libgcj.so.6.0.0)
at
gnu.java.net.LineInputStream.LineInputStream(java.io.InputStream) (/
usr/lib/libgcj.so.6.0.0)
at gnu.java.net.protocol.http.Request.dispatch() (/usr/lib/
libgcj.so.6.0.0)
at gnu.java.net.protocol.http.HTTPURLConnection.connect() (/usr/lib/
libgcj.so.6.0.0)
at gnu.java.net.protocol.http.HTTPURLConnection.getInputStream() (/
usr/lib/libgcj.so.6.0.0)
at java.net.URL.openStream() (/usr/lib/libgcj.so.6.0.0)
at ImageDownloader.run() (Unknown Source)
at .GC_start_routine (/usr/lib/libgcj.so.6.0.0)
at .__clone (/lib/libc-2.3.6.so)
Thread 2: Ending
Thread 2: the input stream close call
failed:java.lang.NullPointerException
java.lang.NullPointerException
at ImageDownloader.run() (Unknown Source)
at .GC_start_routine (/usr/lib/libgcj.so.6.0.0)
at .__clone (/lib/libc-2.3.6.so)
Thread 1: Ending
//END PROGRAM OUTPUT
If I just run one thread/stream, then even the Red Hat machine is
happy. The threads seem to start and end ok and behave correctly. I
just can't get a second call to openStream to work.
Is there some configuration of linux/java that doesn't permit two
streams to be opened at the same time? At first, I thought it might
be a complete lack of ephemeral ports above 1024, but that doesn't
appear to be the problem after all. I haven't been able to find anyone
else that has ever experienced this problem.
gdhurst
// BEGIN TESTURL CLASS
import java.io.*;
public class TestURL {
static boolean listening = true;
public static void main(String[] args) throws IOException {
System.out.println("Starting TestURL");
ImageDownloader id1 = null;
ImageDownloader id2 = null;
id1 = new ImageDownloader("http://www.visnat.com/entry/vnimages/
workplace1.jpg","1");
id2 = new ImageDownloader("http://www.visnat.com/entry/vnimages/
justthetv.gif","2");
System.out.println("Starting the threads...");
id1.start();
id2.start();
System.out.println("End of TestURL after starting threads...");
}
}
// END TESTURL CLASS
// BEGIN IMAGEDOWNLOADER CLASS
import java.io.*;
import java.net.*;
public class ImageDownloader extends Thread {
private String strUrl;
private String TID;
public ImageDownloader(String theurl,String threadID) {
strUrl = theurl;
TID = threadID;
}
public void run() {
URL url;
InputStream is = null;
System.out.println("Thread " + TID + ": Starting");
System.out.println("Thread " + TID + ": URL is " + strUrl);
try {
url = new URL(strUrl);
is = url.openStream(); //throws an IOException
} catch (Exception e) {
System.out.println("Thread " + TID + ": the url openstream call
failed:" + e);
e.printStackTrace();
}
System.out.println("Thread " + TID + ": Ending");
try {
is.close();
} catch (Exception e) {
System.out.println("Thread " + TID + ": the input stream close
call failed:" + e);
e.printStackTrace();
}
} //END RUN()
}
// END IMAGEDOWNLOADER CLASS
this post. This app works fine on several machines, but not on the Red
Hat linux server that I really need it to run on. On the Red Hat
machine, I get the following program output and stack traces.
//BEGIN PROGRAM OUTPUT
Starting TestURL
Starting the threads...
Thread 1: Starting
Thread 1: URL is http://www.visnat.com/entry/vnimages/workplace1.jpg
End of TestURL after starting threads...
Thread 2: Starting
Thread 2: URL is http://www.visnat.com/entry/vnimages/justthetv.gif
Thread 2: the url openstream call
failed:java.lang.NullPointerException
java.lang.NullPointerException
at
gnu.java.net.LineInputStream.LineInputStream(java.io.InputStream,
java.lang.String) (/usr/lib/libgcj.so.6.0.0)
at
gnu.java.net.LineInputStream.LineInputStream(java.io.InputStream) (/
usr/lib/libgcj.so.6.0.0)
at gnu.java.net.protocol.http.Request.dispatch() (/usr/lib/
libgcj.so.6.0.0)
at gnu.java.net.protocol.http.HTTPURLConnection.connect() (/usr/lib/
libgcj.so.6.0.0)
at gnu.java.net.protocol.http.HTTPURLConnection.getInputStream() (/
usr/lib/libgcj.so.6.0.0)
at java.net.URL.openStream() (/usr/lib/libgcj.so.6.0.0)
at ImageDownloader.run() (Unknown Source)
at .GC_start_routine (/usr/lib/libgcj.so.6.0.0)
at .__clone (/lib/libc-2.3.6.so)
Thread 2: Ending
Thread 2: the input stream close call
failed:java.lang.NullPointerException
java.lang.NullPointerException
at ImageDownloader.run() (Unknown Source)
at .GC_start_routine (/usr/lib/libgcj.so.6.0.0)
at .__clone (/lib/libc-2.3.6.so)
Thread 1: Ending
//END PROGRAM OUTPUT
If I just run one thread/stream, then even the Red Hat machine is
happy. The threads seem to start and end ok and behave correctly. I
just can't get a second call to openStream to work.
Is there some configuration of linux/java that doesn't permit two
streams to be opened at the same time? At first, I thought it might
be a complete lack of ephemeral ports above 1024, but that doesn't
appear to be the problem after all. I haven't been able to find anyone
else that has ever experienced this problem.
gdhurst
// BEGIN TESTURL CLASS
import java.io.*;
public class TestURL {
static boolean listening = true;
public static void main(String[] args) throws IOException {
System.out.println("Starting TestURL");
ImageDownloader id1 = null;
ImageDownloader id2 = null;
id1 = new ImageDownloader("http://www.visnat.com/entry/vnimages/
workplace1.jpg","1");
id2 = new ImageDownloader("http://www.visnat.com/entry/vnimages/
justthetv.gif","2");
System.out.println("Starting the threads...");
id1.start();
id2.start();
System.out.println("End of TestURL after starting threads...");
}
}
// END TESTURL CLASS
// BEGIN IMAGEDOWNLOADER CLASS
import java.io.*;
import java.net.*;
public class ImageDownloader extends Thread {
private String strUrl;
private String TID;
public ImageDownloader(String theurl,String threadID) {
strUrl = theurl;
TID = threadID;
}
public void run() {
URL url;
InputStream is = null;
System.out.println("Thread " + TID + ": Starting");
System.out.println("Thread " + TID + ": URL is " + strUrl);
try {
url = new URL(strUrl);
is = url.openStream(); //throws an IOException
} catch (Exception e) {
System.out.println("Thread " + TID + ": the url openstream call
failed:" + e);
e.printStackTrace();
}
System.out.println("Thread " + TID + ": Ending");
try {
is.close();
} catch (Exception e) {
System.out.println("Thread " + TID + ": the input stream close
call failed:" + e);
e.printStackTrace();
}
} //END RUN()
}
// END IMAGEDOWNLOADER CLASS