1class TestMultiPriority1 extends Thread{
2 public void run(){
3 System.out.println("running thread name is:"+Thread.currentThread().getName());
4 System.out.println("running thread priority is:"+Thread.currentThread().getPriority());
5
6 }
7 public static void main(String args[]){
8 TestMultiPriority1 m1=new TestMultiPriority1();
9 TestMultiPriority1 m2=new TestMultiPriority1();
10 m1.setPriority(Thread.MIN_PRIORITY);
11 m2.setPriority(Thread.MAX_PRIORITY);
12 m1.start();
13 m2.start();
14
15 }
16}
1//Sol1
2PriorityQueue<Integer> queue = new PriorityQueue<>(10, Collections.reverseOrder());
3
4
5//Sol2
6// PriorityQueue<Integer> pq = new PriorityQueue<>((x, y) -> y - x);
7PriorityQueue<Integer> pq =new PriorityQueue<>((x, y) -> Integer.compare(y, x));
8
9
10//Sol3
11PriorityQueue<Integer> pq = new PriorityQueue<Integer>(defaultSize, new Comparator<Integer>() {
12 public int compare(Integer lhs, Integer rhs) {
13 if (lhs < rhs) return +1;
14 if (lhs.equals(rhs)) return 0;
15 return -1;
16 }
17});