Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Is sockets and input/output-streams thread-safe?

843790Mar 8 2007 — edited Mar 9 2007
Hi

When creating a simple socket client application I would usually use BufferedReader on the inputstream, PrintWriter on the outputstream and a regular socket as the foundation running within its own thread and responding to events from the Swing UI. Now the question is:

Is for instance the Socket.close() and PrintWriter.write() methods thread safe? Will it lead to problems if these are called from other or perhaps even several other threads? If so, how can I fix this?

I have been googling for this for a while without any significant results, and no tutorials/examples of this scenario has done anything to protect against potential thread issues.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 6 2007
Added on Mar 8 2007
4 comments
3,950 views