If I call two .readUTF methods of one DataInputStream object in two different streams, which one will read information first? Which was called first, or which was called second?
Asked
Active
Viewed 95 times
-2
-
3The blue one? Your question isn't clear at all: one or two streams? Threads involved? – Mat Oct 06 '13 at 08:01
-
Very unclear question. Do you mean you call them in two different threads? – Jim Garrison Oct 06 '13 at 08:01
1 Answers
1
A DataInputStream is associated with one underlying stream. It cannot have multiple streams.
It can be accessed by multiple thread with careful locking. In this situation the first to return would be the first to obtain the lock. Without careful locking, you will get random errors.

Peter Lawrey
- 525,659
- 79
- 751
- 1,130
-
-
1@user2851275 Trying to use a DataInputStream from multiple threads should be avoided unless you have a very clear idea what you are doing and why you are doing it. Most likely it will just add bugs and confusion for no benefit. – Peter Lawrey Oct 06 '13 at 08:08