I have a problem that I'm having trouble coming up with a good idea for.
I have an array of InputStreams, and I want to make a method called listen, that listens to all of these InputStreams. Whenever an InputStream receives data, it's stored into a byte array called input.
Now the problem here is two-fold. I want to run this listen method constantly, while I also run the rest of my program, that is, my program doesn't lock up due to waiting for some input. But I'm not sure how to achieve this. I'm using an anonymous inner class Thread right now, but it seems to me that there must be a better, easier way.
Also, since I'm storing the data into the same variable regardless of which InputStream receives it, I naturally want any InputStreams to wait with overwriting the input variable, until the InputStream currently accessing it is done with it. How would I accomplish this?
Listening to several InputStreams at the same time
Started by ThemePark, Nov 08 2009 05:28 PM
3 replies to this topic
#1
Posted 08 November 2009 - 05:28 PM
|
|
|
#2
Posted 09 November 2009 - 08:35 AM
Threads with resource locks.
#3
Posted 09 November 2009 - 09:16 AM
So there's no other way than using Threads to achieve this? No keyword or anything I can add instead?
#4
Posted 09 November 2009 - 10:21 AM
If you want them to all be able to listen without pausing the program, you're looking at doing either threads or some form of frequent polling.


Sign In
Create Account


Back to top









