真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

001JAVA多線程實(shí)例對(duì)象鎖與類鎖

package com.skcc.mthread;

創(chuàng)新互聯(lián)專注于彭澤企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè),購(gòu)物商城網(wǎng)站建設(shè)。彭澤網(wǎng)站建設(shè)公司,為彭澤等地區(qū)提供建站服務(wù)。全流程定制網(wǎng)站,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)

public class MuiltThread {

private static int num = 0;

public MuiltThread() {
    // TODO Auto-generated constructor stub
}

/****
 *   synchronized void printNum(String tag)  代表 synchronized鎖定的MuiltThread實(shí)例對(duì)象鎖(m1,m2兩者間互不影響)
 *   static  synchronized void printNum(String tag) 代表synchronized 競(jìng)爭(zhēng)的是MuiltThread類鎖 
 * 
 * ****/
public static  synchronized void printNum(String tag) {
    try {
        if(tag.equals("a")) {
            num = 100;
            System.out.println("tag a,num 100 set over.");
            //Thread.sleep(1000);
        }
        else {
            num=200;
            System.out.println("tag b,num 200 set over.");
        }
        System.out.println("tag is " + tag + "  num is "+ num);
    } catch (Exception e) {
        // TODO: handle exception
    }
}

public static void main(String[] args) {
    // TODO Auto-generated method stub

    MuiltThread m1 = new MuiltThread();
    MuiltThread m2 = new MuiltThread();

    Thread t1 = new Thread(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            //m1.printNum("a");
            MuiltThread.printNum("a");
        }
    });

    Thread t2 = new Thread(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub

// m2.printNum("b");
MuiltThread.printNum("b");
}
});

    t1.start();
    t2.start();
}

}


網(wǎng)站標(biāo)題:001JAVA多線程實(shí)例對(duì)象鎖與類鎖
網(wǎng)址分享:http://weahome.cn/article/jdiohs.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部