-2

Below is what I have seen on java t point about thread scheduler.

Thread Scheduler in Java

Thread scheduler in java is the part of the JVM that decides which thread should run.

There is no guarantee that which runnable thread will be chosen to run by the thread scheduler.

Only one thread at a time can run in a single process.

The thread scheduler mainly uses preemptive or time slicing scheduling to schedule the threads.

Community
  • 1
  • 1
Fouad
  • 13
  • 3

4 Answers4

2

The source you are quoting sounds somehow outdated. In present day JVM implementations, Java uses underlying operating system threads.

In other words: a Java thread is mapped by the JVM to a thread provided by the operating system. See here for example.

In that sense, the "true" multi-threading capabilities of your system very much depend on the JVM implementation/version and the OS type/version; and even the capabilities of the underlying hardware. But rest assured: on a current day system, Java is able to run many threads in "real parallel".

In your context - Java used "green threads" at some point (and then Java would manage the threads) - but that is computer science history (many many years in the past). See here for example.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • @Fouad : You should read about Green threads in Java and then understand the difference between Green threads vs modern day threads. – Geek Jul 25 '17 at 13:23
1

Thread scheduler in java is the part of the JVM that decides which thread should run.

Close, but... Most JVMs that anybody uses for real work in the last couple of decades use "native threading". That means, that scheduling is the operating system's job. The JVM does not get involved.

There is no guarantee [of] which runnable thread will [next] be chosen to run by the thread scheduler.

True but..., The operating system implements a thread scheduling policy (It may be capable of implementing any of several policies, to be chosen by the system administrator). If you understand the policy, then you could, in principle, know which thread will be scheduled next.

But true, because the Java Language Specification does not say anything about thread scheduling policies, and if you're writing a "run anywhere" Java program, then you should not depend on any particular policy.

Only one thread at a time can run in a single process.

False, but... It was true, maybe thirty years ago. Virtually all computers, tablets, and cell phones these days have more than one processor. At any given instant, there can be one thread running on each processor.

The thread scheduler mainly uses preemptive or time slicing scheduling to schedule the threads.

Yes. The thread scheduler on any given OS doesn't mainly do whatever, it implements a policy. On most computers, tablets, and cell phones the policy choices all will be preemptive. That means that a thread could be be de-scheduled at any point in time (e.g., half way through an i++; statement).

The alternative to preemptive multi-tasking is called cooperative multitasking, in which a thread can lose its turn on the processor only at certain, well defined yield points. That's what Thread.yield() is for, but I don't know where you are ever going to find Java running in a cooperative multitasking environment.

Solomon Slow
  • 25,130
  • 5
  • 37
  • 57
0

You can run more than one thread in a process at the same time if your machine supports that.

Geek
  • 23,089
  • 20
  • 71
  • 85
  • @Fouad where the underlying operational system supports multithreading, today it effectively means everything – gusto2 Jul 25 '17 at 09:34
  • I always feel inclined to upvote content of people who give helpful feedback ... but here, I just can't. This is really just a statement. You give no explanations. Nothing. This would be a mediocre comment, but an answer ... sorry, no. – GhostCat Jul 25 '17 at 13:28
0

Information you have is very obsolete. What you describe was valid for OS when each process was effectviely a single thread (Windows 3.1, or OLD unix kernels, Macintosh system 7). That time JVM running as a single process had to implement its own thread scheduler and thread management.

Today all common platforms support natively multithreading and by default JVM uses the underlying system implementation

gusto2
  • 11,210
  • 2
  • 17
  • 36