File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Unable to read from the Socket Input Stream in a multithreaded environment with wait and notify Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "Unable to read from the Socket Input Stream in a multithreaded environment with wait and notify" Watch "Unable to read from the Socket Input Stream in a multithreaded environment with wait and notify" New topic
Author

Unable to read from the Socket Input Stream in a multithreaded environment with wait and notify

Mohamed Sanaulla
Bartender

Joined: Sep 08, 2007
Posts: 2925
    
  15

I am using 2 threads- ReaderThread for reading from the Socket input stream and the WriterThread for writing to the socket output stream. Both of them work fine when am just writing to the stream and not reading from the stream. But when am also Reading from the input stream the program doesn't run further, it hangs.

Below is the code which does the writing- Its in the WriterThread class.

The above code- Reads from the command line, writes it to the socket outputstream using the "writer" object.

Below is the code which reads from the stream- Its in the ReaderThread class



The above code does the reading from the Socket's input stream. The problem wit the above code is it waits indefinitely after printing- "Reader Running". But when i comment out the code from Line-Beg to Line-End it executes properly giving chance for the other WriterThread to write to the output stream. Why is it so?

Note: "response" is a common object which is being used for synchronization. Also am closing the "server socket" once the main method completed execution. Also the client socket is a "C" socket.

PS: Am not sure if this should be in Thread forum. Cause i dont see any problems with the "wait" and "notify" being used.

Mohamed Sanaulla | My Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to read from the Socket Input Stream in a multithreaded environment with wait and notify
 
Similar Threads
Reg. Threads
JTextarea and JScrollPane
Echo client/server application
the exec command is not able to deal with space some time
Threaded Application won't run.