Example usage for java.lang Thread setPriority

List of usage examples for java.lang Thread setPriority

Introduction

In this page you can find the example usage for java.lang Thread setPriority.

Prototype

public final void setPriority(int newPriority) 

Source Link

Document

Changes the priority of this thread.

Usage

From source file:ThreadDemo.java

public static void main(String args[]) {
    Thread t = new Thread(new ThreadDemo(), "java2s.com thread");
    t.setPriority(1);

    System.out.println("thread  = " + t);

    t.start();/*from   ww w  .j a  va  2  s. c om*/
}

From source file:ThreadDemo.java

public static void main(String args[]) {

    // thread created
    Thread t = new Thread("java2s.com thread");
    // set thread priority
    t.setPriority(1);
    // prints thread created
    System.out.println("thread  = " + t);
    // this will call run() function
    t.start();//from  ww  w  . j a  v  a 2  s . co m
}

From source file:MainClass.java

public static void main(String args[]) {
    Thread t = Thread.currentThread();
    t.setName("My Thread");
    t.setPriority(1);
    System.out.println("current thread: " + t);
    int active = Thread.activeCount();
    System.out.println("currently active threads: " + active);
    Thread all[] = new Thread[active];
    Thread.enumerate(all);//from  w  w  w .j a  va 2  s.co  m
    for (int i = 0; i < active; i++) {
        System.out.println(i + ": " + all[i]);
    }
    Thread.dumpStack();
}

From source file:ThreadDemo.java

public static void main(String args[]) {
    Thread t = new Thread(new ThreadDemo(), "java2s.com thread");
    // set thread priority
    t.setPriority(1);
    // print thread created
    System.out.println("thread  = " + t);
    // this will call run() function
    t.start();//  w  ww .j  a  v  a  2  s .  co  m
}

From source file:Main.java

public static void main(String[] args) {

    Thread t = Thread.currentThread();
    t.setName("java2s.com thread");
    // set thread priority to 1
    t.setPriority(1);

    System.out.println("Thread = " + t);

    int count = Thread.activeCount();
    System.out.println("currently active threads = " + count);
}

From source file:Main.java

public static void main(String[] args) {

    Thread t = Thread.currentThread();
    t.setName("java2s.com thread");
    // set thread priority to 1
    t.setPriority(Thread.NORM_PRIORITY);

    System.out.println("Thread = " + t);

    int count = Thread.activeCount();
    System.out.println("currently active threads = " + count);
}

From source file:Main.java

public static void main(String[] args) {

    Thread t = Thread.currentThread();
    t.setName("java2s.com thread");
    // set thread priority to 1
    t.setPriority(Thread.MIN_PRIORITY);

    System.out.println("Thread = " + t);

    int count = Thread.activeCount();
    System.out.println("currently active threads = " + count);
}

From source file:Main.java

public static void main(String[] args) {

    Thread t = Thread.currentThread();
    t.setName("java2s.com thread");
    // set thread priority to 1
    t.setPriority(Thread.MAX_PRIORITY);

    System.out.println("Thread = " + t);

    int count = Thread.activeCount();
    System.out.println("currently active threads = " + count);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Thread thread1 = new Thread(new TestThread(1));
    Thread thread2 = new Thread(new TestThread(2));

    thread1.setPriority(Thread.MAX_PRIORITY);
    thread2.setPriority(Thread.MIN_PRIORITY);

    thread1.start();/*ww w  .  j  av  a  2 s .  c o  m*/
    thread2.start();

    thread1.join();
    thread2.join();
}

From source file:PriorityCompete.java

public static void main(String[] args) {
    Runnable r = new Runnable() {
        public void run() {
            System.out.println("Run without using yield()");
            System.out.println("=========================");
            runSet(false);/*  ww w. j a  va 2 s  .com*/

            System.out.println();
            System.out.println("Run using yield()");
            System.out.println("=================");
            runSet(true);
        }
    };

    Thread t = new Thread(r, "Priority");
    t.setPriority(Thread.MAX_PRIORITY - 1);
    t.start();
}