java实时优先级高于应有的优先级

时间:2018-03-14 14:21:08

标签: java real-time jamaicavm

  

***警告:Java实时优先级> = 11无法使用,优先级为10(原因:操作不允许)

目前正在尝试一个带有此错误消息的项目。

在Vmware,eclipse ide和jamaica vm中使用Xfce环境

这实际上有什么问题?当系统优先级为10时,java实时优先级大于11的错误状态,如何设置优先级更高?

我的代码

package realtime;
import javax.realtime.*;


class seconds extends RealtimeThread{

    int secs = 0;
    int mins = 0;
    int hours=0;


    public seconds(SchedulingParameters sched, ReleaseParameters rel)
    {
        super(sched,rel);
    }
    public void run() {
        while(true) {
            secs++;

            System.out.println("seconds" + secs);
            if(secs>58) {
                mins ++;
                secs = 0;
            }
            boolean ok = waitForNextPeriod();
        }
    }

}

class minutes extends RealtimeThread{
    private minutes min = null;
    private seconds sec = null;
    int mins = 0;
    int hours = 0;

    public minutes(SchedulingParameters sched, ReleaseParameters rel)
    {
        super(sched,rel);
    }

    public void run() {
        while(true) {
            mins++;

            System.out.println("minutes" + mins);
            if(mins>58) {
                hours ++;
                mins = 0;
            }
            boolean ok = waitForNextPeriod();
        }
    }

}

class hours extends RealtimeThread{
    private minutes min = null;
    private seconds sec = null;
    private hours hour=null;
    int mins = 0;
    int hours = 0;
    int day =0;

    public hours(SchedulingParameters sched, ReleaseParameters rel)
    {
        super(sched,rel);
    }

    public void run() {
        while(true) {
            mins++;

            System.out.println("hours" + hours);
            if(hours>24) {
                day ++;
                hours= 0;
            }
            boolean ok = waitForNextPeriod();
        }
    }

}


public class Q1 {
    private minutes min = null;
    private seconds sec = null;
    private hours hour = null;

    Q1(){
        PriorityParameters hoursched = new PriorityParameters(PriorityScheduler.instance().getMaxPriority());
        ReleaseParameters hoursrel = new PeriodicParameters(new RelativeTime(59*59*1000,1000));
        PriorityParameters minsched = new PriorityParameters(PriorityScheduler.instance().getMinPriority());
        ReleaseParameters minrel = new PeriodicParameters(new RelativeTime(59000,1000));
        PriorityParameters secsched = new PriorityParameters(PriorityScheduler.instance().getMaxPriority());
        ReleaseParameters secrel = new PeriodicParameters(new RelativeTime(1000,0));

        hour = new hours(hoursched,hoursrel);
        min = new minutes(minsched, minrel);
        sec = new seconds(secsched, secrel);

        hour.start();
        min.start();
        sec.start();
    }   

    public static void main(String[] args) {
        Q1 t = new Q1();
    }


}

1 个答案:

答案 0 :(得分:3)

这是JamaicaVM手册中的常见问题解答:

答案是:

  

“操作系统不允许创建具有实时优先级的线程。相反,JamaicaVM创建了一个具有正常优先级的线程。这意味着实时调度不可用,并且应用程序可能无法正常工作正常。

     

在现成的Linux系统上,使用实时优先级需要超级用户权限。也就是说,启动应用程序   sudo将解决此问题。或者,可以通过编辑/etc/security/limits.conf并将rtprio设置为使用的最大本机优先级来更改特定用户或组的优先级限制。对于JamaicaVM在Linux上使用的默认优先级映射,设置rtprio   限制为80就足够了。“