java160107ThreadTest
来源:互联网 发布:社交网络上的跟风行为 编辑:程序博客网 时间:2024/05/17 00:01
/**
* 创建两个线程,和主线程交替运行
* 线程调用两点class className extends Thread
* 在className中覆盖run(),run中写自己要交给线程要做的demo
* 在调用类中由className的实例调用 start()即可
*
*/
package java160107;
/**
* @author LiZheng
*
*/
public class ThreadTest {
/**
* @param args
*/
public static void main(String[] args) {
// Test test1 = new Test("one");
// Test test2 = new Test("two");
// Test test1 = new Test();
// Test test2 = new Test();
Test test1 = new Test("one++");
Test test2 = new Test("two++");
test1.start();
test2.start();
for (int i = 0; i < 60; i++) {
System.out.println("main-----" + i);
}
}
}
class Test extends Thread {
// private String name;
// public Test(String name) {
// this.name=name;
// }
public Test(String name) {
// this.name=name;
super(name);
}
@Override
public void run() {
super.run();
for (int x = 0; x < 60; x++) {
// System.out.println(name+"---test run---" + x);
// System.out.println(this.getName() + "---test run---" + x);
System.out.println(Thread.currentThread().getName() + "---test run---" + x);
}
}
}
* 创建两个线程,和主线程交替运行
* 线程调用两点class className extends Thread
* 在className中覆盖run(),run中写自己要交给线程要做的demo
* 在调用类中由className的实例调用 start()即可
*
*/
package java160107;
/**
* @author LiZheng
*
*/
public class ThreadTest {
/**
* @param args
*/
public static void main(String[] args) {
// Test test1 = new Test("one");
// Test test2 = new Test("two");
// Test test1 = new Test();
// Test test2 = new Test();
Test test1 = new Test("one++");
Test test2 = new Test("two++");
test1.start();
test2.start();
for (int i = 0; i < 60; i++) {
System.out.println("main-----" + i);
}
}
}
class Test extends Thread {
// private String name;
// public Test(String name) {
// this.name=name;
// }
public Test(String name) {
// this.name=name;
super(name);
}
@Override
public void run() {
super.run();
for (int x = 0; x < 60; x++) {
// System.out.println(name+"---test run---" + x);
// System.out.println(this.getName() + "---test run---" + x);
System.out.println(Thread.currentThread().getName() + "---test run---" + x);
}
}
}
0 0
- java160107ThreadTest
- REST技术第三步 @BeanParam的使用
- hdoj 1501 Zipper
- leetcode--Evaluate Reverse Polish Notation
- android关于canvas.rotate()研究
- SparkML实战之五:SVM
- java160107ThreadTest
- 开个博客记录日语学习
- 数据库-表连接
- Oracle树查询(查询所有子节点,父节点等等)
- Postman 简单实用 提高编程效率
- 如何移植openwrt系统
- Redis+Spring缓存实例(windows环境,附实例源码及详解)
- GreenPlum常用时间函数
- cannot change version of project facet Dynamic web module to 2.5