multithreading - JAVA: managing DataInputStream on multiple threads using same socket -
Basically, I have a main thread that will accept a socket and get a dataInstream object And then can pass this input object to different sub threads where they will use it for the data obtained and will do various tasks. But this will not work because both the threads are using the same object so that they can hear that when a user sends something, I do not know who can read it. I still have the idea:
1- Create in some way the organizer receives incoming requests and redirects them to the responsible thread (I'm not sure how to do this).
2- When a thread is expecting a sequence of incoming requests (based on time), other threads have to sleep so that it can capture inputstream (which I'm not sure is done ).
How to apply any other ideas or how? Thanks!
(In the worst case, I must be in the same formula.)
< P> I recommend that you have used
ReadWriteLock , look at its API and examples in depth.
Comments
Post a Comment