Ist Java präventiv?

Ich habe viele Antworten auf diese Frage gesehen, bin mir aber immer noch nicht sicher.

Eines davon war "Java ist präventiv". (Die JVM plant mithilfe eines präemptiven, prioritätsbasierten Planungsalgorithmus (normalerweise Round-Robin-Algorithmus).

Das zweite war, dass wenn 2 Threads mit der gleichen Priorität ausgeführt werden, Java dies nicht verhindert und ein Thread verhungern könnte.

Jetzt habe ich ein Programm geschrieben, um es auszuprobieren. Ich habe 10 Threads mit minimaler Priorität erstellt, gefolgt von 10 Threads mit maximaler Priorität. Das Ergebnis war, dass ich zwischen allen Threads hin und her springe - was bedeutet, dass Java präemptiv ist, auch wenn zwei Threads gleich sind Priorität

 /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @
 */
public class JavaApplication1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        for (int i=0;i<10;i++){
            Thread t=new Thread(new Dog(i));
            t.setPriority(Thread.MIN_PRIORITY);
            t.start();
        }

        try {
            Thread.sleep(5000);
        } catch (InterruptedException ex) {
            Logger.getLogger(JavaApplication1.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i = 0; i < 10; i++) {
            Thread g = new Thread(new Dog(i+10));
            g.setPriority(Thread.MAX_PRIORITY);
            g.start();
        }

    }
}

t

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

/**
 *
 * @author Matan2t
 */
public class Dog implements Runnable{
    public int _x=-1;
    public Dog(int x){
        _x=x;
    }
    @Override
    public void run(){
        while(true){
            System.out.println("My Priority Is : " + _x);
        }
    }

}

Antworten auf die Frage(1)

Ihre Antwort auf die Frage