0

私がやろうとしているのは、次のようなcertiant値を持つプロセス(これは単なるオブジェクトです)を持つことです。

public String name;
public int priority; //not to exceed 4
public int serviceTimeTotal; //holds the cumlitive service time
public int waitTimeTotal; //holds the cumulative wait time
public int arrivalTime;
public int burstTime;
public boolean added;
public boolean active;
public boolean isDone;

また、各プロセスがサービスを取得する時間と、他のプロセスがサービスを取得するまで各プロセスが待機する時間を追跡したいと思います。時間を正確に追跡しているかどうかはわかりませんが、ミリ秒単位の時間が必要で、それが何であるかを考えています。.nanoTimeを使用しているプログラムを実行すると、プログラムは実行されますが、待機時間はまったく増加しませんが、実行中のもののサービス時間は長くなるので、私はそれを正しく理解したと思います。

   public static void runLevelOne(LinkedList<MyProcess> ll, MyProcess mp)
{
    int start = 0;

    mp.active = true;
   System.out.println("Running Level One Queue");
    //runs for 3 millseconds
    while(start <= 3000)
    {
        //cheak to see if process is over
       if(mp.burstTime <= mp.serviceTimeTotal)
        {
            mp.isDone = true;
            System.out.println(mp.name + " has completed its task");
            mp.active = false;
            //get rid of it from the queue
            ll.remove(mp);
            break;

        }


        try {
            //run proccess
            Thread.sleep(3);
        } catch (InterruptedException ex) {
            Logger.getLogger(PartATwo.class.getName()).log(Level.SEVERE, null, ex);
        }


        start += System.nanoTime()/ 1000000;
        mp.serviceTimeCalculator(start);
        mp.calculatePriority();
        //make all other proccesses in ll wait
        for(MyProcess s :ll)
        {
            s.waiting(start);
            System.out.println(s.name+  " wait time: " + s.waitTimeTotal);
        }
        System.out.println(mp.name + " new priority is: " + mp.priority);
    }
    mp.active = false;

}

これにより、プロセスが実行され、リンクリスト内の各プロセスのサービス時間、優先度、および待機時間が計算されます。

MyProcessクラスでは、次のように優先度を計算します

public int calculatePriority()
{
    System.out.println("Starting Priority " + priority);
    System.out.println("service time " + serviceTimeTotal);
    System.out.println("waitTimeTotal " + waitTimeTotal);

    priority = (serviceTimeTotal + waitTimeTotal) / serviceTimeTotal;
    if(priority <= 1.5)
    {
        priority = 1;
    }
    if(priority > 1.6 && priority <= 2.5 )
    {
        priority = 2;
    }
    if(priority > 2.6 && priority <= 3.5)
    {
        priority = 3;
    }
    if(priority > 3.6 && priority > 3.5)
    {
        priority = 4;
    }
    return priority;
}

そしてこのようなサービス時間と待ち時間

  public  void waiting(int time)
{
    if(active = false)
    {
        waitTimeTotal += time;
    }
}
 public void serviceTimeCalculator(int time)
{
    serviceTimeTotal += time;
}

この継ぎ目は機能するはずですが、機能しません。私はここで何かが欠けていますかこれで助けてくれてありがとう

4

1 に答える 1

1

まず、時間の値を分割しても、 のlong代わりに使用して時間の値を保持します。int

次に、開始時刻をSystem.getNanos()に設定するのではなく、を使用して設定する必要があります0。次のようなことをします:

long start = System.getNanos() / 1000000;
long end = start;
while (end - start < 3000) {
    ...
    end = System.getNanos() / 1000000;
}
于 2012-10-19T14:11:14.493 に答える