Operating System - HP-UX
1825795 Members
2281 Online
109687 Solutions
New Discussion

Java Thread Problem on HP-UX 11.00

 
Shyam Sundar
Advisor

Java Thread Problem on HP-UX 11.00

Hi,

I have a problem on my HP-UX 11.00 system, while running a simple java program where the serverSocket.accept() method is waiting to accept connections and in a different thread serversocket.close() is issued. On receiving serversocket.close() the behavior is to throw an exception called "SocketException" and come out of serversocket.accept() waiting method.

Below is the behavior (output) in win2k machine. This output occurs in win2k, winNT, Solaris

C:\jdk1.3\bin>java ThreadTest
ThreadTest-main: Entering main method
ThreadTest-main: Created ServerSocket object
CloseServerSocket: Created CloseServerSocket object
ThreadTest-main: Starting the thread which will close the server socket
ThreadTest-main: Waiting to accept connections
CloseServerSocket-run: Entering run method
CloseServerSocket-run: Trying to close serversocket using close method
Exception :java.net.SocketException: socket closed
ThreadTest-main: Exiting main method
CloseServerSocket-run: Successfully closed serversocket using close method
CloseServerSocket-run: Exiting run method

C:\jdk1.3\bin>


The behavior(output) in HP-UX machine

bash-2.04$ ./java ThreadTest
ThreadTest-main: Entering main method
ThreadTest-main: Created ServerSocket object
CloseServerSocket: Created CloseServerSocket object
ThreadTest-main: Starting the thread which will close the server socket
ThreadTest-main: Waiting to accept connections
CloseServerSocket-run: Entering run method
CloseServerSocket-run: Trying to close serversocket using close method


You could see that it never returned to the bash shell prompt, it actually hangs. It never throws the exception and doesn't comes out of the waiting serverSockte.accept() method. This is not the actual behavior. Java handles all socket type functions through native implementations. All we wanted to know is whether any body has encountered such a problem in HP-UX and whether they have any solutions for it.

Please recommend if any patch could solve thish problem.

The same problem is attached in the doc. along with the swlist output of the system.

Thanks and Regards,
Shyam.

1 REPLY 1
Mike Stroyan
Honored Contributor

Re: Java Thread Problem on HP-UX 11.00

Here is the answer from
http://h21007.www2.hp.com/dspp/tech/tech_TechSingleTipDetailPage_IDX/1,2366,1353,00.html
at the "developer & solution partner portal", http://www.hp.com/dspp -
------------------------------------------
closing a socket when accept or read is pending

If a thread is performing an accept or read on a socket, and you try to close the socket to clean up resources, the default behavior is for the close() to block until the accept or read call completes. If you want to change this behavior, you should use the following Java command line option:
-XdoCloseWithReadPending

This option allows one thread to close a socket when there is an outstanding accept or read pending on the same socket from another thread.

With the -XdoCloseWithReadPending option, the socket close() call closes the socket and, in the context of the thread with the pending read or accept, a SocketException with the message "Socket closed" is thrown.

Thanks to Judy Muchowski.