//2015年5月5日16:55:00

//Main

package com.alfredsun.thread;

public class Main {

	public static void main(String[] args) {
// TODO Auto-generated method stub
MyThread t1=new MyThread("A");
MyThread t2=new MyThread("B");
// t1.run();
// t2.run();
//线程的启动由start()
t1.start();
t2.start();
} }

  //MyThread

package com.alfredsun.thread;

public class MyThread extends Thread
{
private String name;
public MyThread(String name)
{
this.name =name;
}
public void run()
{
for(int i=0;i<10;i++)
{
System.out.println(name+":"+i);
}
super.run();
}
}

//并发结果

A:0
B:0
A:1
B:1
A:2
B:2
A:3
B:3
A:4
B:4
A:5
B:5
B:6
A:6
B:7
A:7
B:8
B:9
A:8
A:9

//Runnable接口

//2015年5月5日17:04:03

//main
package com.alfredsun.thread; public class Main { public static void main(String[] args) {
// TODO Auto-generated method stub
MyRunable r1= new MyRunable("A");
MyRunable r2=new MyRunable("B");
Thread t1=new Thread(r1);
Thread t2=new Thread(r2);
t1.start();
t2.start();
} }
//Myrunnable
package com.alfredsun.thread; public class MyRunable implements Runnable
{
private String name;
public MyRunable(String name)
{
this.name=name;
}
public void run()
{
for(int i=0;i<1000;i++)
{
System.out.println(name+":"+i);
}
}
}

//线程的操作

//2015年5月5日17:31:47

 package com.alfredsun.thread;
class RunnableDemo implements Runnable
{
private String name;
public RunnableDemo(String name) {
this.name =name;
}
public void run()
{
for(int i=0;i<50;i++)
{
System.out.println(Thread.currentThread().getName());
}
}
}
public class test {
public static void main(String[] args)
{
RunnableDemo r1= new RunnableDemo("A");
RunnableDemo r2= new RunnableDemo("B");
Thread t1 =new Thread(r1);
Thread t2 =new Thread(r2); t1.start();
t2.start();
}
}

最新文章

  1. apache ab测试命令详解
  2. 试验删除RAC(ORA10G)节点
  3. sim800 gprs发送数据的AT流程
  4. 揭秘Facebook首个数据中心:全球15亿用户的账户信息都在这里
  5. 论文笔记之:Generative Adversarial Text to Image Synthesis
  6. postgresql 锁的定位
  7. 接收ET采集器数据页面
  8. POJ ---2531
  9. 查看Ubuntu操作系统位数
  10. WINDOWS UPDAET
  11. C#字符串的比较
  12. asp.net js 获取服务器控件值
  13. ORM框架 EF - code first 的封装 优化一
  14. Spring Cloud Alibaba 新版本发布:众多期待内容整合打包加入!
  15. Objective-C中整数与字符串的相互转换
  16. [物理学与PDEs]第1章习题12 Coulomb 规范下电磁场的标势、矢势满足的方程
  17. dom4j 通过 org.dom4j.XPath 设置命名空间来支持 带namespace 的 xpath
  18. ES系列十六、集群配置和维护管理
  19. panda核心数据结构
  20. Dependency Parsing -13 chapter(Speech and Language Processing)

热门文章

  1. Memcached在.Net中的基本操作
  2. DDD 回归具体的业务场景,Domain Model 再再重新设计
  3. [转]Android图片下载
  4. Orchard Module,Theme,Core扩展加载概述
  5. 如何让Fortran生成不同的随机数
  6. 【WCF系列二:如何调用WCF服务】WCF入门教程(图文)VS2012
  7. 记录OC学习的一点一滴(二)
  8. JS 浏览器检测
  9. 职责链(Chain of Responsibility)模式
  10. Load ContextCLR 探测