-2

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?

1 Answers1

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
  • I meant two different threads. My English... – Serhii Tereshchenko Oct 06 '13 at 08:04
  • 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