Example usage for java.lang Thread MIN_PRIORITY

List of usage examples for java.lang Thread MIN_PRIORITY

Introduction

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

Prototype

int MIN_PRIORITY

To view the source code for java.lang Thread MIN_PRIORITY.

Click Source Link

Document

The minimum priority that a thread can have.

Usage

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) 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();//from  www .  jav a 2  s.  c  om
    thread2.start();

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

From source file:Main.java

public static void main(String[] args) {
    Thread t = Thread.currentThread();
    System.out.println("main Thread  Priority:" + t.getPriority());

    Thread t1 = new Thread();
    System.out.println("Thread(t1) Priority:" + t1.getPriority());

    t.setPriority(Thread.MAX_PRIORITY);
    System.out.println("main Thread  Priority:" + t.getPriority());

    Thread t2 = new Thread();
    System.out.println("Thread(t2) Priority:" + t2.getPriority());

    // Change thread t2 priority to minimum
    t2.setPriority(Thread.MIN_PRIORITY);
    System.out.println("Thread(t2) Priority:" + t2.getPriority());
}

From source file:com.autodomum.example.Example1.java

public static void main(String[] args) throws Exception {
    final ConfigurableApplicationContext context = SpringApplication.run(Example1.class, args);
    final JsonLampDao jsonLampDao = context.getBean(JsonLampDao.class);
    final EventComponent eventComponent = context.getBean(EventComponent.class);
    final EventContext eventContext = context.getBean(EventContext.class);
    final TelldusComponent telldusComponent = context.getBean(TelldusComponent.class);
    final NashornScriptComponent nashornScriptComponent = context.getBean(NashornScriptComponent.class);

    final Thread eventComponentThread = new Thread(eventComponent);
    eventComponentThread.setDaemon(true);
    eventComponentThread.setPriority(Thread.MIN_PRIORITY);
    eventComponentThread.setName("EventComponent");
    eventComponentThread.start();/*from ww w.  ja  v a2 s .  com*/

    // Coordinates of Stockholm
    eventContext.setCoordinate(new Coordinate(18.063240d, 59.334591d));

    eventComponent.updateEventContext();
    eventComponent.register(LampStateChangedEvent.class, telldusComponent);

    final Thread telldusComponentThread = new Thread(telldusComponent);
    telldusComponentThread.setDaemon(true);
    telldusComponentThread.setPriority(Thread.MIN_PRIORITY);
    telldusComponentThread.setName("Telldus");
    telldusComponentThread.start();

    try (InputStream inputStream = Example1.class.getResourceAsStream("/lamps.json")) {
        jsonLampDao.load(inputStream);
    }

    try (InputStream inputStream = Example1.class.getResourceAsStream("/ai.js")) {
        nashornScriptComponent.replaceScript(inputStream);
    }
}

From source file:rems.Program.java

/**
 * @param args the command line arguments
 *///  w w  w . j  av a  2 s  .c o  m
public static void main(String[] args) {
    try {

        Global.UsrsOrg_ID = 3;
        Global.dataBasDir = "C:\\1_DESIGNS\\MYAPPS\\Enterprise_Management_System\\Enterprise_Management_System\\bin\\Debug\\Images\\test_database";
        Global.rnnrsBasDir = "C:\\1_DESIGNS\\MYAPPS\\Enterprise_Management_System\\Enterprise_Management_System\\bin\\Debug\\bin";

        String pname = ManagementFactory.getRuntimeMXBean().getName();
        if (pname.contains("@")) {
            Global.pid = Integer.parseInt(pname.substring(0, pname.lastIndexOf("@")));
        } else {
            Global.pid = Thread.currentThread().getId();
        }
        Global.HostOSNme = System.getProperty("os.name");
        System.out.println(Global.pid);
        System.out.println(Global.HostOSNme);

        String[] macDet = Global.getMachDetails();
        System.out.println(Arrays.toString(macDet));
        System.out.println(args.length);
        System.out.println(Arrays.toString(args));
        Global.errorLog += Global.pid + System.getProperty("line.separator") + Global.HostOSNme
                + System.getProperty("line.separator") + Arrays.toString(Global.getMachDetails())
                + System.getProperty("line.separator");
        //Global.writeToLog();
        if (args.length >= 8) {
            Global.rnnrsBasDir = StringUtils.strip(args[7], "\"");
            runnerName = StringUtils.strip(args[5], "\"");
            Global.errorLog = args[0] + System.getProperty("line.separator") + args[1]
                    + System.getProperty("line.separator") + args[2] + System.getProperty("line.separator")
                    + "********************" + System.getProperty("line.separator") + args[4]
                    + System.getProperty("line.separator") + args[5] + System.getProperty("line.separator")
                    + args[6] + System.getProperty("line.separator") + Global.rnnrsBasDir
                    + System.getProperty("line.separator");

            if (args.length >= 10) {
                Global.callngAppType = StringUtils.strip(args[8], "\"");
                Global.dataBasDir = StringUtils.strip(args[9], "\"");
                Global.errorLog += args[8] + System.getProperty("line.separator") + args[9]
                        + System.getProperty("line.separator");
                if (args.length == 11) {
                    Global.AppUrl = StringUtils.strip(args[10], "\"");
                    Global.errorLog += args[10] + System.getProperty("line.separator");
                }
            }
            Global.errorLog += "PID: " + Global.pid + " Running on: " + macDet[0] + " / " + macDet[1] + " / "
                    + macDet[2];
            Global.writeToLog();
            Global.runID = Long.valueOf(args[6]);
            do_connection(args[0], args[1], args[2], args[3], args[4]);
            Global.appStatPath = Global.rnnrsBasDir;
            //Program.updateRates("2015-07-02");
            if (Global.runID > 0) {
                Global.rnUser_ID = Long.valueOf(
                        Global.getGnrlRecNm("rpt.rpt_report_runs", "rpt_run_id", "run_by", Global.runID));
                Global.UsrsOrg_ID = Global.getUsrOrgID(Global.rnUser_ID);
            }

            if (!Global.globalSQLConn.isClosed()) {
                Global.globalSQLConn.close();
                boolean isLstnrRnng = false;
                if (Program.runnerName.equals("REQUESTS LISTENER PROGRAM")) {
                    int isIPAllwd = Global.getEnbldPssblValID(macDet[2],
                            Global.getEnbldLovID("Allowed IP Address for Request Listener"));
                    int isDBAllwd = Global.getEnbldPssblValID(Global.Dbase,
                            Global.getEnbldLovID("Allowed DB Name for Request Listener"));
                    if (isIPAllwd <= 0 || isDBAllwd <= 0) {
                        Program.killThreads();
                        Thread.currentThread().interrupt();
                        //Program.killThreads();
                        return;
                    }

                    isLstnrRnng = Global.isRunnrRnng(Program.runnerName);
                    if (isLstnrRnng == true) {
                        Program.killThreads();
                        Thread.currentThread().interrupt();
                        //Program.killThreads();
                        return;
                    }
                }
                Global.errorLog = "Successfully Connected to Database\r\n" + String.valueOf(isLstnrRnng)
                        + System.getProperty("line.separator");
                Global.writeToLog();
                String rnnPryty = Global.getGnrlRecNm("rpt.rpt_prcss_rnnrs", "rnnr_name", "crnt_rnng_priority",
                        Program.runnerName);

                if (isLstnrRnng == false && Program.runnerName.equals("REQUESTS LISTENER PROGRAM")) {
                    Global.updatePrcsRnnrCmd(Program.runnerName, "0", -1);
                    thread1 = new RqstLstnrUpdtrfunc("ThreadOne");
                    thread1.setDaemon(true);
                    thread1.setName("ThreadOne");
                    thread1.setPriority(Thread.MIN_PRIORITY);
                    //System.out.println("Starting ThreadOne thread...");
                    thread1.start();
                    Global.minimizeMemory();
                    if (Program.runnerName.equals("REQUESTS LISTENER PROGRAM")) {
                        //Thread for Generating Run Requests for Scheduled Programs/Reports
                        thread2 = new GnrtSchldRnsfunc("ThreadTwo");
                        thread2.setDaemon(true);
                        thread2.setName("ThreadTwo");
                        thread2.setPriority(Thread.MIN_PRIORITY);
                        //System.out.println("Starting ThreadTwo thread...");
                        thread2.start();

                        //Thread for Generating Run Requests for Scheduled Alerts
                        thread6 = new GnrtSchldAlertsfunc("ThreadSix");
                        thread6.setDaemon(true);
                        thread6.setName("ThreadSix");
                        thread6.setPriority(Thread.MIN_PRIORITY);
                        //System.out.println("Starting ThreadSix thread...");
                        thread6.start();

                        //Thread for Monitoring Scheduled Request Runs that are due but not running
                        // and starting their appropriate process runners
                        thread3 = new MntrSchdldRqtsNtRnngfunc("ThreadThree");
                        thread3.setDaemon(true);
                        thread3.setName("ThreadThree");
                        thread3.setPriority(Thread.MIN_PRIORITY);
                        //System.out.println("Starting ThreadThree thread...");
                        thread3.start();

                        //Thread for Monitoring User Request Runs that are due but not running
                        // and starting their appropriate process runners
                        thread4.setDaemon(true);
                        thread4.setName("ThreadFour");
                        thread4.setPriority(Thread.MIN_PRIORITY);
                        //System.out.println("Starting ThreadFour thread...");
                        thread4.start();

                        //Thread for Generating Run Requests for Scheduled Alerts
                        thread7 = new MntrSchdldAlertsNtRnngfunc("ThreadSeven");
                        thread7.setDaemon(true);
                        thread7.setName("ThreadSeven");
                        thread7.setPriority(Thread.MIN_PRIORITY);
                        //System.out.println("Starting ThreadSeven thread...");
                        thread7.start();

                        //Thread for Running Requests for User Initiated Alerts
                        thread8 = new MntrUserAlertsNtRnngfunc("ThreadEight");
                        thread8.setDaemon(true);
                        thread8.setName("ThreadEight");
                        thread8.setPriority(Thread.MIN_PRIORITY);
                        //System.out.println("Starting ThreadEight thread...");
                        thread8.start();
                    }
                } else {
                    //Thread for running the actual Code behind the Request Run if this is the
                    //Program supposed to run that request
                    //i.e. if Global.runID >0
                    Global.minimizeMemory();
                    if (Global.runID > 0) {
                        thread1 = new RqstLstnrUpdtrfunc("ThreadOne");
                        thread1.setDaemon(true);
                        thread1.setName("ThreadOne");
                        thread1.setPriority(Thread.MIN_PRIORITY);
                        //System.out.println("Starting ThreadOne thread...");
                        thread1.start();

                        thread5 = new RunActualRqtsfunc("ThreadFive");
                        thread5.setDaemon(true);
                        thread5.setName("ThreadFive");
                        //System.out.println("Starting ThreadFive thread...");
                        if (rnnPryty.equals("1-Highest")) {
                            thread1.setPriority(Thread.MAX_PRIORITY);
                        } else if (rnnPryty.equals("2-AboveNormal")) {
                            thread1.setPriority(7);
                        } else if (rnnPryty.equals("3-Normal")) {
                            thread1.setPriority(Thread.NORM_PRIORITY);
                        } else if (rnnPryty.equals("4-BelowNormal")) {
                            thread1.setPriority(3);
                        } else {
                            thread1.setPriority(1);
                        }
                        thread5.start();
                    }
                    // Allow counting for 10 seconds.
                    //Thread.Sleep(1000);
                }
            }
        }
    } catch (NumberFormatException ex) {
        Global.errorLog = ex.getMessage() + System.getProperty("line.separator")
                + Arrays.toString(ex.getStackTrace());
        String fileLoc = Global.rnnrsBasDir + "/log_files/";
        Date dNow = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("ddMMMyyyyHHmmss");
        fileLoc += "Global.errorLog" + ft.format(dNow.getTime()) + ".rho";
        PrintWriter fileWriter;
        try {
            fileWriter = new PrintWriter(fileLoc, "UTF-8");
            fileWriter.println(Global.errorLog);
            fileWriter.close();
        } catch (FileNotFoundException ex1) {
            Logger.getLogger(Program.class.getName()).log(Level.SEVERE, null, ex1);
        } catch (UnsupportedEncodingException ex1) {
            Logger.getLogger(Program.class.getName()).log(Level.SEVERE, null, ex1);
        }
        killThreads();
    } catch (SQLException ex) {
        Global.errorLog = ex.getMessage() + System.getProperty("line.separator")
                + Arrays.toString(ex.getStackTrace());
        String fileLoc = Global.rnnrsBasDir + "/log_files/";
        Date dNow = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("ddMMMyyyyHHmmss");
        fileLoc += "Global.errorLog" + ft.format(dNow.getTime()) + ".rho";
        PrintWriter fileWriter;
        try {
            fileWriter = new PrintWriter(fileLoc, "UTF-8");
            fileWriter.println(Global.errorLog);
            fileWriter.close();
        } catch (FileNotFoundException ex1) {
            Logger.getLogger(Program.class.getName()).log(Level.SEVERE, null, ex1);
        } catch (UnsupportedEncodingException ex1) {
            Logger.getLogger(Program.class.getName()).log(Level.SEVERE, null, ex1);
        }
        killThreads();
    } finally {

    }
}

From source file:Main.java

public static Thread getLowPriorityBackgroundThread(Runnable runnable) {
    Thread thread = getBackgroundThread(runnable);
    thread.setPriority(Thread.MIN_PRIORITY + 1); // keep other stuff running
    // smoothly/*ww w .j a va 2 s  .c  om*/
    return thread;
}

From source file:Test.java

public Test() {
    Runnable runner = new MyRunnable("First");
    Thread t = new Thread(runner);
    t.setPriority(Thread.MIN_PRIORITY);
    t.start();//from   w  ww. j ava  2s.c om
    runner = new MyRunnable("Second");
    t = new Thread(runner);
    t.setPriority(Thread.MAX_PRIORITY);
    t.start();
}

From source file:MyServlet.java

public void init() throws ServletException {
    searcher = new Thread(this);
    searcher.setPriority(Thread.MIN_PRIORITY);
    searcher.start();/*from   ww w  .java2  s. c om*/
}

From source file:org.sipfoundry.sipxconfig.common.LazyDaemon.java

public LazyDaemon(String name, int sleepInterval) {
    super(name);
    m_sleepInterval = sleepInterval;
    setPriority(Thread.MIN_PRIORITY);
    setDaemon(true);
}

From source file:AppletAnimation.java

public void run() {
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

    long startTime = System.currentTimeMillis();

    Thread currentThread = Thread.currentThread();

    while (currentThread == animatorThread) {
        frameNumber++;/*from   www. j av  a2  s.c  o m*/

        repaint();

        try {
            startTime += delay;
            Thread.sleep(100);
        } catch (InterruptedException e) {
            break;
        }
    }
}