-1

The read() method blocks until a byte is available on stream for an input resource(keyboard/file/network/program).

public abstract int read() throws IOException

1) For a single threaded Java program, Does blocking of read() enable kernel to move java process to blocked state?

2) For a multi-threaded Java program, Does blocking of read() on one thread allow other threads to occupy CPU slice? Having java process continue in Running state until it's CPU time slice.

overexchange
  • 15,768
  • 30
  • 152
  • 347
  • 1
    Realistically, you will not be able to find a single-threaded Java process. The JVM itself spawns multiple threads. – Andrew Henle Oct 26 '17 at 23:12
  • @AndrewHenle Are you talking about JVM system threads? GC/compiler/VM/.. that will be part of my java program in runtime – overexchange Oct 26 '17 at 23:14
  • 1
    Processes does not have states like that, only threads do. – David Schwartz Oct 26 '17 at 23:15
  • Processes have states in unix-like OSs, at least as far as users are concerned. sleeping, zombie, stopped, etc. Check out the `ps` man page, "PROCESS STATE CODES". – Paul Hicks Oct 26 '17 at 23:20
  • @DavidSchwartz Do you mean, user level thread(java's `t.start()`-> C's `pthread_create()`) map to kernel level thread? OS schedules kernel level threads, with it's respective [threading model](https://stackoverflow.com/questions/26324668/why-does-os-require-maintain-kernel-threads) – overexchange Oct 26 '17 at 23:43
  • Please stop re-posting this question. – user207421 Oct 26 '17 at 23:45
  • 1
    @PaulHicks An unfortunate and confusing historical relic that exists only within the `ps` command. There is simply no way a process can sleep -- that's a category error. – David Schwartz Oct 27 '17 at 00:02

1 Answers1

1

For a single threaded Java program, Does blocking of read() enable kernel to move java process to blocked state?

There is no such thing as a single-threaded Java program, but if there was, yes.

For a multi-threaded Java program, Does blocking of read() on one thread allow other threads to occupy CPU slice?

Of course. Otherwise threads would be pointless.

Having java process continue in Running state until it's CPU time slice.

Yes.

user207421
  • 305,947
  • 44
  • 307
  • 483