Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8720489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:03:12+00:00 2026-06-13T07:03:12+00:00

what I am trying to do is to have a process (this is just

  • 0

what I am trying to do is to have a process (this is just a object) with certiant values like:

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;

And I want to keep track of how much time each process gets service and how much time each process waits whle the other process gets service. I dont know if im keeping track of the time right or not I want the time in milliseconds and I think thats what it is in, im using the .nanoTime When I run the program it runs but the wait time does not increase at all but the service time for the one that is running does increase so I think I got that one right
So here is how I am dong this

   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;

}

This runs the process and then calculates the service time, priority, and th wait time for each process in the linked list.

In the MyProcess class I calculate the priority like this

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;
}

and the service time and wait time like this

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

This seams like it should work but it does not. am i missing something here
Thanks for any help with this

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:03:14+00:00Added an answer on June 13, 2026 at 7:03 am

    First of all, use a long instead of an int to hold the time values, even if you divide them.

    Then, you need to set the start time using System.getNanos() too, instead of setting it to 0. Do something like:

    long start = System.getNanos() / 1000000;
    long end = start;
    while (end - start < 3000) {
        ...
        end = System.getNanos() / 1000000;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a process that I'm trying to automate in which I have to
I have a process under the Run key in the registry. It is trying
I'm trying to figure out how XSLT process namespace prefixes and have following example:
I am currently trying to communicate a parent process which should have multiple children
I am trying to automate my trigger process so that I don't have to
I'm trying to create a depth of field post process, but have no idea
I have some code where the timer EventHandler has this void timer_Tick(object sender, EventArgs
I have a fluent interface for an IoC container registration process, and this contains
Just trying to get a handle on blocks. I get the concept. They're like
I don't think this is a duplicate, but I just might not be using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.