0

according to the following resources, thread scheduling is done by either operation system or JVM or both.

1.http://tutorials.jenkov.com/java-concurrency/creating-and-starting-threads.html

2.https://www.javatpoint.com/thread-scheduler-in-java

MY QUESTION:

1.who schedules the thread?

2.does the thread scheduler gets overridden anywhere?(like OS thread being overridden by JVM thread scheduler)

3.how do i change from preemptive scheduling to time slicing scheduling ? or vice versa?

amarnath harish
  • 945
  • 7
  • 24
  • 2
    I think you're looking at old resources. The operating system schedules threads. You should not be dealing with concurrency at this low level. You should be using JDK and the new concurrency package. – duffymo May 30 '17 at 16:49
  • please explain what is concurrency package? – amarnath harish May 30 '17 at 16:54
  • https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/package-summary.html – duffymo May 30 '17 at 16:55
  • Please read [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) before attempting to ask more questions. –  May 30 '17 at 17:14

2 Answers2

4
  1. who schedules the thread?

Operating System. Though, at application level, your JRE can schedule application-level threads based on the thread priority; still it'll get scheduled finally by the scheduler(scheduling block) of OS. User level threads are managed by a user level library, but they still require a kernel system call to operate.

  1. does the thread scheduler gets overridden anywhere?(like OS thread being overridden by JVM thread scheduler)

The Java runtime environment supports a very simple, deterministic scheduling algorithm called fixed-priority scheduling. The actual scheduler is unique in OS; and looks after scheduling of threads from overall perspective, not from Java/application level perspective.

  1. how do i change from preemptive scheduling to time slicing scheduling ? or vice versa?

You can't change the nature of scheduling of scheduler, unless you modify the OS kernel, which is lower-level stuff. Even in JRE, you can't change the thread scheduling at the application level.

Attribution: Thread Scheduling tutorial.

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73
  • May I know why the downvote? – Am_I_Helpful May 30 '17 at 17:14
  • I suspect the intention behind the downvoting is to make sure this question doesn't get an upvoted answer that would prevent it from getting deleted. I wouldn't take it as a criticism of your post's content. – Nathan Hughes May 30 '17 at 17:23
-1
  1. JVM Schedules a Java Thread(Though in reality it is the OS doing it).

  2. There is no single Java Virtual Machine; JVM is a specification, and there are multiple implementations of it, including the OpenJDK version and the Sun version of it, among others. Any reasonable JVM would simply use the underlying threading mechanism provided by the OS otherwise there can be discrepencies, which would imply POSIX Threads (pthreads) on UNIX (Mac OS X, Linux, etc.) and would imply WIN32 threads on Windows. Typically, those systems use a round-robin strategy by default.

3.In general the JVM doesn't do any scheduling. That is the task of the OS. Linux for example has configurable scheduling options, and if you want to add a new scheduling strategy, you can change the kernel.

However, depending on why you want to do this, you can solve the problem another way such as using a custom Executor, or a Reactor style framework, or effectively disabling scheduling for a CPU and doing all the work in Java yourself.

Anmol Parikh
  • 23
  • 1
  • 2
  • 4