<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Concurrency - sleeping priority

    Sleeping
    A simple way to affect the behavior of your tasks is by calling sleep( ) to cease (block) the execution of that task for a given time.
    If you must control the order of execution of tasks, your best bet is to use synchronization controls.
    public class SleepingTask extends LiftOff{
        
    public void run(){
            
    try {
                
    while(countDown-- > 0){
                    System.out.print(status());
                    
    // Old-style:
                    
    // Thread.sleep(100);
                    
    // Java SE5/6-style
                    TimeUnit.MICROSECONDS.sleep(100);
                }
            } 
    catch (InterruptedException e) {
                
    // TODO: handle exception
            }
        }
        
        
    public static void main(String[] args)  {
            ExecutorService exec 
    = Executors.newCachedThreadPool();
            
    for(int i=0; i<5; i++)
                exec.execute(
    new SleepingTask());
            exec.shutdown();
        }
    }


    Priority
    The priority of a thread conveys the importance of a thread to the scheduler.
    However, this doesn’t mean that threads with lower priority aren’t run (so you can’t get deadlocked because of priorities).
    Lower-priority threads just tend to run less often.
    Trying to manipulate thread priorities is usually a mistake.

    Although the JDK has 10 priority levels, this doesn’t map well to many operating systems.
    public class SimplePriorities implements Runnable {
        
    private int countDown = 5;
        
    private volatile double d; //No optimization
        private int priority;
        
    public SimplePriorities(int priority){
            
    this.priority = priority;
        }
        
        
    public String toString(){
            
    return Thread.currentThread() + "" + countDown;
        }

        @Override
        
    public void run() {
            Thread.currentThread().setPriority(priority);
            
    while(true){
                
    // An expensive, interruptable operation
                for(int i=1; i<10000; i++){
                    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.newCachedThreadPool();
            
    for(int i=0; i<5; i++)
                exec.execute(
    new SimplePriorities(Thread.MIN_PRIORITY));
            exec.execute(
    new SimplePriorities(Thread.MAX_PRIORITY));
            exec.shutdown();
        }
    }
















    posted on 2012-11-21 10:56 鹽城小土包 閱讀(142) 評論(0)  編輯  收藏 所屬分類: J2EE

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統計

    常用鏈接

    留言簿

    隨筆檔案(14)

    文章分類(18)

    文章檔案(18)

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 日韩成人精品日本亚洲| 特级毛片免费观看视频| 无码国产精品一区二区免费vr| 一级做a爰片性色毛片免费网站 | 两性色午夜视频免费播放| 亚洲第一网站男人都懂| 男女超爽视频免费播放| 亚洲日韩在线中文字幕第一页| 91亚洲导航深夜福利| 91精品视频在线免费观看| 亚洲成人福利网站| 任你躁在线精品免费| 国产成人亚洲精品青草天美| 午夜老司机永久免费看片| 亚洲另类精品xxxx人妖| 好爽…又高潮了免费毛片| 猫咪免费观看人成网站在线| 国产亚洲精品拍拍拍拍拍| 午夜老司机永久免费看片| 亚洲人成电影网站久久| 91免费国产精品| 狠狠综合久久综合88亚洲| 久久久久久免费一区二区三区| 亚洲黄片毛片在线观看| 成人爽a毛片免费| 亚洲Av无码一区二区二三区| 日韩在线不卡免费视频一区| 亚洲国产精品白丝在线观看| 国产大片51精品免费观看| 中文字幕看片在线a免费| 亚洲国产高清在线精品一区| 免费jjzz在在线播放国产| 亚洲精品无码专区在线播放| gogo全球高清大胆亚洲| 中文字幕免费在线| 亚洲AV无码一区二区大桥未久| 一个人看www在线高清免费看| 亚洲精品欧洲精品| 免费jjzz在线播放国产| 在线观看亚洲专区| 亚洲宅男永久在线|