简单的Java多线程演示
2008-02-20 20:07
357 查看
import java.util.*;
public class Tshow{
Runnable r1 = new t1();
Runnable r2 = new t2();
Thread th1 = new Thread(r1);
Thread th2 = new Thread(r2);
public void GetInts() throws Exception{
System.out.println("Int1=" + Integer.toString(((t1)r1).getX()) + "/t/tIntY=" + Integer.toString(((t2)r2).getY()));
Thread.sleep(100);
GetInts();
}
public void loop(){
try{
th1.start();
th2.start();
GetInts();
}catch(Exception e){System.out.println(e);}
}
public static void main(String agrt[]){
Tshow k = new Tshow();
k.loop();
}
}
class t1 implements Runnable{
int intX = 0;
public void run(){
try{
intX++;
Thread.sleep(300);
run();
}catch(Exception e){}
}
public int getX(){
return intX;
}
}
class t2 implements Runnable{
int intY = 1000000;
public void run(){
try{
intY--;
Thread.sleep(100);
run();
}catch(Exception e){}
}
public int getY(){
return intY;
}
}
public class Tshow{
Runnable r1 = new t1();
Runnable r2 = new t2();
Thread th1 = new Thread(r1);
Thread th2 = new Thread(r2);
public void GetInts() throws Exception{
System.out.println("Int1=" + Integer.toString(((t1)r1).getX()) + "/t/tIntY=" + Integer.toString(((t2)r2).getY()));
Thread.sleep(100);
GetInts();
}
public void loop(){
try{
th1.start();
th2.start();
GetInts();
}catch(Exception e){System.out.println(e);}
}
public static void main(String agrt[]){
Tshow k = new Tshow();
k.loop();
}
}
class t1 implements Runnable{
int intX = 0;
public void run(){
try{
intX++;
Thread.sleep(300);
run();
}catch(Exception e){}
}
public int getX(){
return intX;
}
}
class t2 implements Runnable{
int intY = 1000000;
public void run(){
try{
intY--;
Thread.sleep(100);
run();
}catch(Exception e){}
}
public int getY(){
return intY;
}
}
相关文章推荐
- 简单的Java1.4版synchronized多线程的死锁演示
- Java多线程-一个简单的线程,实现挂起和恢复的功能
- 最简单的java多线程代码(重写thread或者runnable的run方法)
- Java入门到精通——基础篇之多线程实现简单的PV操作的进程同步
- java多线程卖票-教你简单易懂三步骤
- java多线程程序设计一、简单多线程的实现
- java 多线程简单的工具类
- Java-使用Callable实现多线程的之JDK源码简单学习实践
- Java实例开发05-01 简单的多线程服务器
- 用JAVA实现简单爬虫多线程抓取
- 简单的java多线程源码分享(一)
- 用 Java 实现一个简单的多线程 web 服务器
- java多线程-简单的卖票程序
- java 多线程机制简单总结
- Java 多线程 简单实例 (消费者与生成者)的关系
- 记事本运行java文件实现简单的多线程
- 简单直观-实战体会Java多线程编程的精要 (5)
- java实现多线程的一种简单方式
- Java多线程简单示例
- Java中的多线程简单介绍(带代码)