4个进程?你是不是还运行着别的java程序呀?
这个程序只有3个线程~
我在我机上试过了
一条主线程跟你创建的tp1,tp2线程Thread.activeCount()
Returns the number of active threads in the current thread's thread group.默认的是系统线程组,你线程组里是不是有有其他程序的线程?
这个程序只有3个线程~
我在我机上试过了
一条主线程跟你创建的tp1,tp2线程Thread.activeCount()
Returns the number of active threads in the current thread's thread group.默认的是系统线程组,你线程组里是不是有有其他程序的线程?
解决方案 »
- static
- 代码格式化器里有,把分号与最末字符插入一个空格吗?我觉得分号靠在太近了..
- 帮忙推荐一本java图像处理的书啊!!50分!
- 如果设置JApplet所有的button都不可用
- 关于取SQL里面图片字段的问题?
- 请问部署在同一个应用服务上的两个不同的war包,其中一个能否用类反射机制读到另一个war包的类信息?
- 菜鸟问题...提交数据不成功,请帮忙看看!...在线等
- 初学者100分求助:关于applet GUI的问题!
- JBuilder中,Frame中的控件怎么没法改变大小呀,好像控制不了布局
- 程序员7里面提到的java2 sdk源代码根本下载不了
- 初学者问一个很简单的问题,快来捡分呀!!
- *****探讨:怎样将存储在数据库中的二进制数据还原成自定义的java类实例?******
import java.util.*;
class TimePrinter extends Thread {
int pauseTime;
String name;
public TimePrinter(int x, String n) {
pauseTime = x;
name = n;
}
public void run() {
while(true)
{
try {
System.out.println(name + ":" + new
Date(System.currentTimeMillis()));
Thread.sleep(pauseTime);
get();
} catch(Exception e)
{
System.out.println(e);
}
}
}
static public void main(String args[]) {
TimePrinter tp1 = new TimePrinter(1000, "Fast Guy"); TimePrinter tp2 = new TimePrinter(5000, "Slow Guy"); tp2.start();
tp1.start();
//
Thread[] array = new Thread [10];
int i = Thread.enumerate( array );
for (int j=0 ; j< i ; j++)
{
System.out.println( "------------" + array[j].getName());
} System.out.println("------------" + Thread.activeCount());
//} private void get()
{
Thread[] array = new Thread [10];
int i = Thread.enumerate( array );
for (int j=0 ; j< i ; j++)
{
System.out.println( "------------" + array[j].getName());
} System.out.println("------------" + Thread.activeCount());}
} ==============================================================我的运行结果是:D:\csdn_test>java TimePrinter
------------main
------------Thread-1
------------Thread-2
------------4
Fast Guy:Mon Apr 26 11:01:59 CST 2004
Slow Guy:Mon Apr 26 11:01:59 CST 2004
------------Thread-1
------------Thread-2
------------DestroyJavaVM
------------4
Fast Guy:Mon Apr 26 11:02:00 CST 2004
------------Thread-1
------------Thread-2
------------DestroyJavaVM
------------4