• Post Reply Bookmark Topic Watch Topic
  • New Topic

multithreading problem.....urgent

 
rajarshi dutta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a single session say I am running 5 threads all r trying to access a method which have used input/output stream.When one thread entered the method....it used the input/output stream and closes it.At same point of time some other thread when trying to execute the method its throwing exception like either input stream is close or inputstream read fully.I overcome the problem by synchronizing the method.My question is how can we implement multithreading without synchronizing the method or using synchronized statement...i mean without synchronizing input/output streams object.Any help...plz?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rajarshi dutta
Welcome to JavaRanch!

In an effort to help you get the most from our forums, we've compiled a
list of tips for asking questions here. You can find the list in our
FAQ section here.

In particular, please see UseRealWords.
Abbreviations such as "u" or "ur" in place of "you" and "you are"
or "you're" confound language translation software making it hard
for our non-English speaking members to read your posts.

Also, you've posted this in the servlets forum.
See:
CarefullyChooseOneForum
I'll move this to our "Threads and Synchronization" forum for you.

Most importantly see: EaseUp to find out why putting "urgent" in your subject line will almost always keep you from getting a speedy response.



Again, welcome to JavaRanch and good luck with your question.
-Ben
[ July 21, 2006: Message edited by: Ben Souther ]
 
Ernesto Elias-Nieland
Ranch Hand
Posts: 53
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there is no other solution than synchronizing the method that uses the stream.
 
Henry Wong
author
Sheriff
Posts: 22533
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well... if you are willing to redesign the method, it should be possible. What is the method doing with the stream? Is each call going to a different file?

If so, then you can have local variables to prevent the different calls from stepping on each other. If not, you will have to redesign it to work with each other -- for example, not close the stream until everyone is done.

And what does it mean to work with each other? I am pretty sure parts of the data will have to be written in a synchronized fashion, but if you can figure out what parts needs to be written together, you can only synchronize those smaller sections of code.

Good luck,
Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!