多线程简单样例
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();
}
}
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();
}
}
相关文章推荐
- php文件上传与下载
- 整理bookstore遇到的问题及解决办法
- Jackson转换Json
- 【JQuery】stop()函数
- 居中布局的几种方式
- 20145327 《Java程序设计》第五周学习总结
- SDAU课程练习2 1026
- python3用http.server模块搭建简易版服务器
- 【10-2】复杂表达式
- GridLayout网格布局
- My study note of PHP language(IV)
- 关于mysql中的like语句带参数问题
- AB --- APACHE自带的压力测试工具 (APACHE BENCHMARK )
- 字节码操作_javassist库_动态创建新类_属性_方法_构造器_API详解JAVA216-217
- PyQt4颜色对话框QColorDialog
- Eclipse下配置Tomcat
- Eclipse下配置Tomcat
- Eclipse下配置Tomcat
- Eclipse下配置Tomcat
- Eclipse下配置Tomcat