| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 639 人关注过本帖
标题:一个简单的线程问题
只看楼主 加入收藏
大嘴先生2
Rank: 1
等 级:新手上路
威 望:2
帖 子:815
专家分:0
注 册:2006-4-17
收藏
得分:0 

public class TryThread extends Thread
{
int time;
TryThread(int time)
{
this.time=time;
}
public void run()
{
try
{
for(int i=0;i<30;i++)
System.out.println("我是线程甲,是守护线程");
sleep(time);
}
catch(InterruptedException e)
{
System.out.println(e.toString());
}
}
}
public class TryThread2 extends Thread
{
int time;
TryThread2(int time)
{
this.time=time;
}
public void run()
{
try
{
for(int i=0;i<30;i++)
System.out.println("我是线程乙,是用户线程");
sleep(time);
}
catch(InterruptedException e)
{
System.out.println(e.toString());
}
}
}

public class Xiancheng implements Runnable
{
public static void main()
{
Thread read=new TryThread(163);
Thread read2=new TryThread2(2004);
read.setDaemon(true);
read2.setDaemon(false);
read.start();
read2.start();
Xiancheng a=new Xiancheng();
Thread b=new Thread(a);
b.start();
}
public void run()
{
try
{
for(int i=0;i<30;i++)
{
System.out.println("我是主线程");
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
//这回是完整程序了
//还是不行!
谁给看看

骑白马的未必是王子,也可能是唐僧;有翅膀的未必是天使,也可能是鸟人。
2007-05-31 09:56
大嘴先生2
Rank: 1
等 级:新手上路
威 望:2
帖 子:815
专家分:0
注 册:2006-4-17
收藏
得分:0 
这回程序完整了
只是上面2个子类的
public 忘记去掉了
因为原来是放在3个文件的!

骑白马的未必是王子,也可能是唐僧;有翅膀的未必是天使,也可能是鸟人。
2007-05-31 11:20
快速回复:一个简单的线程问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015093 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved