您的位置:首页 > 其它

多线程简单样例

2016-04-03 00:00 274 查看
摘要: 经常记不住多线程写法,在这里mark一下,以便快速使用。

public class DemoMain {

public static void main(String[] args) {

start();

}

private static void start() {

Thread a = new Thread(new Runnable() {

@Override

public void run() {

while(true)

{

System.out.println("A");

try {

//wait(500);

Thread.sleep(5000);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

});

Thread b = new Thread(new Runnable() {

@Override

public void run() {

while(true)

{

System.out.println("B");

try {

//wait(3);

Thread.sleep(3000);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

});

a.start();

b.start();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: