Java Programming thought notes---concurrent priority __ Programming

Source: Internet
Author: User
 2017/7/31 created 
* * JDK 10 priority and operating system mapping is not good, so only recommended max_priority,norm_priority,min_priority * Three priority/public class Simplepriorities Impl
    Ements Runnable {private int countdown=5;
    Prevent the compiler from optimizing the variable D private volatile double D;
    private int priority;
    public simplepriorities (int priority) {this.priority=priority;
    Public String toString () {return thread.currentthread () + ":" +countdown; The priority of the @Override public void Run () {//thread should be set within run because the thread only has a valid Thread.CurrentThread () priority set after running. SE
        Tpriority (priority); while (true) {for (int i = 0; I < 10000 i++) {//When the divisor is 0 o'clock, the program does not throw an exception because 0 in double is not really 0 or 0.0 and
                is a very long//may be 0.000000000001 or other, so a positive number divided by 0.0 results will be very big d+= (MATH.PI+MATH.E)/(double) I;
                if (i%1000==0) {Thread.yield ();
            } System.out.println (this);
 if (--countdown==0) {return;           }} public static void Main (string[] args) {Executorservice Exec=executors.newcache
        Dthreadpool ();
        for (int i = 0; i < 5; i++) {Exec.execute (new simplepriorities (thread.min_priority));
        } exec.execute (New Simplepriorities (thread.max_priority));
    Exec.shutdown ();
 }

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.