传统线程(一)
2016-01-16 15:49
429 查看
package com.ygl;
public class TraditionThread {
public static void main(String[] args) {
//**************************************
Thread thread=new Thread(){
@Override
public void run() {
while(true)
try {
Thread.sleep(500);
System.out.println(Thread.currentThread().getName());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
thread.start();
//**************************************
Thread thread2=new Thread(new Runnable(){
@Override
public void run() {
while(true)
try {
Thread.sleep(500);
System.out.println(Thread.currentThread().getName());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
thread2.start();
//**************************************
new Thread(new Runnable(){
@Override
public void run() {
while(true)
try {
Thread.sleep(500);
System.out.println("Runnable"+Thread.currentThread().getName());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}){
//此处执行System.out.println("Thread"+Thread.currentThread().getName());
//而不会找System.out.println("Runnable"+Thread.currentThread().getName());因为被覆盖
public void run() {
while(true)
try {
Thread.sleep(500);
System.out.println("Thread"+Thread.currentThread().getName());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
}
}
public class TraditionThread {
public static void main(String[] args) {
//**************************************
Thread thread=new Thread(){
@Override
public void run() {
while(true)
try {
Thread.sleep(500);
System.out.println(Thread.currentThread().getName());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
thread.start();
//**************************************
Thread thread2=new Thread(new Runnable(){
@Override
public void run() {
while(true)
try {
Thread.sleep(500);
System.out.println(Thread.currentThread().getName());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
thread2.start();
//**************************************
new Thread(new Runnable(){
@Override
public void run() {
while(true)
try {
Thread.sleep(500);
System.out.println("Runnable"+Thread.currentThread().getName());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}){
//此处执行System.out.println("Thread"+Thread.currentThread().getName());
//而不会找System.out.println("Runnable"+Thread.currentThread().getName());因为被覆盖
public void run() {
while(true)
try {
Thread.sleep(500);
System.out.println("Thread"+Thread.currentThread().getName());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
}
}
相关文章推荐
- Winform 通过FlowLayoutPanel及自定义的编辑控件,实现快速构建C/S版的编辑表单页面 z
- hadoop权威指南 chapter1 Meet Hadoop
- Architecture——the main Nodes of configuration for WCF
- ADC采样频率计算与时钟频率选择
- 我身边的应届生
- DB9 公头母头引脚定义及连接
- Android ScrollView嵌套HorizontalScrollView 滑动问题 ScrollView包括GridView显示问题
- EtherCAT数据帧结构
- YTU 2945: 编程:五元向量的运算
- Linux系统80端口被拦截,开启80端口方法
- winform DataGridView控件判断滚动条是否滚动到当前已加载的数据行底部 z
- JSON的三种解析方式
- 我从1万小时编程中学到了什么
- iOS触摸事件深入
- 学习如何使用CSDN-markdown编辑器
- Android动态加载及hook资料汇总
- 推荐一款前端框架pintuer
- 消息重发机制
- 使用Ant过程中的一些小知识点总结
- UI_文本框属性