code: private synchronized void resortInitQueue() {
      Comparator<JobInProgress> comp = new Comparator<JobInProgress>() {
        public int compare(JobInProgress o1, JobInProgress o2) {
          int res = o1.getPriority().compareTo(o2.getPriority());
          if(res == 0) {
            if(o1.getStartTime() < o2.getStartTime())
              res = -1;
            else
              res = (o1.getStartTime()==o2.getStartTime() ? 0 : 1);
          }
            
          return res;
        }
      };
      
      synchronized (jobInitQueue) {
        Collections.sort(jobInitQueue, comp);
      }
    }
docs: Sort jobs by priority and then by start time.