mutiple input streams

i have two different input streams from different locations.

i want to wait for data on these streams and then process that data.

at the moment i have it like:

string a = inputa.readline();

string b = inputb.readline();

if(string a.equals(something){//do soemthing

if(string b.equals(something){//do soemthing else

but obviously this is a bad way of doing it because b may have to wait for datato come on a, and a may have to wait for data to come on b.

what is a simple alternative (pref. without threading).

thanks.

[578 byte] By [apmda] at [2007-11-27 1:40:12]
# 1
If processing inputa and processing inputb are largely independent tasks, why not use multithreading?
DrLaszloJamfa at 2007-7-12 0:54:08 > top of Java-index,Java Essentials,Java Programming...
# 2
they do rather independant tasks but unfortunatly they need to be within the same class for several reasons.is there no other way? would organising the if statement in some other manner work?
apmda at 2007-7-12 0:54:08 > top of Java-index,Java Essentials,Java Programming...
# 3

> they do rather independant tasks but unfortunatly

> they need to be within the same class for several

> reasons.

>

> is there no other way? would organising the if

> statement in some other manner work?

Not if they are truly independent. Consider the case where the code is busy with one event and the other event occurs. What will service it?

Threads, as suggested. Not multiple classes as you said - one class, multiple threads.

ChuckBinga at 2007-7-12 0:54:08 > top of Java-index,Java Essentials,Java Programming...
# 4
> they do rather independant tasks but unfortunatly> they need to be within the same class for several> reasons.The notion of class and Thread are independent.
DrLaszloJamfa at 2007-7-12 0:54:08 > top of Java-index,Java Essentials,Java Programming...
# 5
just need a quick reminder on threads...suppose i have a thread (a) which in turn creates two more threads(1 & 2). once thread A runs to completion will it die or will it wait for both threads 1 & 2 to also die?
apmda at 2007-7-12 0:54:08 > top of Java-index,Java Essentials,Java Programming...
# 6
> once thread A runs to completion will it die or will it wait for both threads 1 & 2 to also die?Unless you are putting in specific code like t.join, it will not wait.
DrLaszloJamfa at 2007-7-12 0:54:08 > top of Java-index,Java Essentials,Java Programming...