Hello,
Below is a some source code for a simple test. You invoke it with a
hostname that has a telnet port (for historical reasons):
java STest localhost
Anyway, it spawns two threads.
SThread opens a socket, unblocks a lock and then pends on a socket
read().
XThread waits on the lock, sleeps for a while and then closes the
socket.
What I expect to happen (and what happens on Linux JDK), is that when
the socket is closed, the read() will throw an exception. What happens
on HP is that the whole thing hangs. The close() hangs, the read()
stays where it is.
I think they have a bug involving blocking I/O (which was a problem with
Linux JDK at one point). Is this really a bug, or is this acceptable
behaviour. Someone please tell me it's a bug. They want to charge me
$250/hr if they investigate it and it's not a bug.
Here's the code:
----------------------------------------
import java.net.*;
import java.util.Date;
public class STest {
public static void main(String[] param) {
if (param.length != 1) {
System.out.println("Usage: java STest <host>");
System.exit(1);
}
SThread t = new SThread(param[0]);
XThread x = new XThread(t);
try {
t.start();
x.start();
x.join();
System.out.println("XThread completed. Socket should be closed");
} catch(Exception e) {
e.printStackTrace();
}
}
}
class XThread extends Thread {
private SThread st;
public XThread(SThread st) { this.st = st; }
public void run() {
try {
st.pause();
System.out.println("XThread sleeping for a little bit.\t" +
new Date());
sleep(5000);
System.out.println("XThread awake.\t\t\t" + new Date());
st.s.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
class SThread extends Thread {
private String host;
public Socket s;
public SThread(String host) { this.host = host; }
public void run() {
try {
// Open a telnet socket to the host passed on the command line
s = new Socket(host, 23);
System.out.println("Unblocking pause()");
synchronized(this) { notifyAll(); }
while(true) {
s.getInputStream().read();
}
} catch(Exception e) {
e.printStackTrace();
}
}
public synchronized void pause() {
try { wait(); } catch(Exception e) { e.printStackTrace(); }
}
}