simple app breaks when opening second stream with openStream

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
 
G

Gordon Beaton

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.

You appear to be using gcj. Do you have the same problem if you use
the JDK from Sun instead?

/gordon

--
 
J

jmail

You appear to be using gcj. Do you have the same problem if you use
the JDK from Sun instead?

/gordon

--

I am using gcj, but I have managed to temporarily procure a second Red
Hat server of even earlier OS vintage and the program works fine with
gcj. There is just something on the one server that doesn't like to
run two streams. I don't think I can get the JDK put on the trouble
machine as it is at our ISP. We will eventually get a new dedicated
server, so this whole question may be rendered moot, but I would still
like to figure out why it fails on the one machine. I may have to just
write it off to some peculiarity of the OS and JVM mixture.

gdhurst
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top