public class hello
{
static
{
Thread t=Thread.currentThread();
System.out.println("current:"+t);
}
}运行后 ,还是会出现 thread[main,5,main]但是我们老师说,应该 拉圾收集线程 也存在的,为什么这里看不到呢?要怎么才能看到呢? 请教高手。
{
static
{
Thread t=Thread.currentThread();
System.out.println("current:"+t);
}
}运行后 ,还是会出现 thread[main,5,main]但是我们老师说,应该 拉圾收集线程 也存在的,为什么这里看不到呢?要怎么才能看到呢? 请教高手。
解决方案 »
- 时间合并算法 .特别向alexandertech提问
- 使用Java怎样获得一个在磁盘中操作的任意一个文件的具体路径?
- java ftp上传不稳定的问题
- 为何有的jar双击能打开,有的只能在cmd下运行?
- 有关子类和父类之间转化的问题
- 两个JPanel的子类互相调用,出现空指针异常,谢谢!
- 如何互相调用文件?????????
- 怎样产生一随机数,请教
- 请教jdk/bin目录下的java.exe和javaw.exe有什么区别?它们分别是管什么的?
- Vector类的addElement()和elementAt()是否具有final属性?
- 如何利用通过程序(java)将pdf格式的文档转换成html格式的文档
- 为什么要CLASSPATH?我只在PATH里加上JDK的bin目录就可以用了。
线程名为:Finalizer 线程组为:system
public class GCTest { /**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
Thread t=Thread.currentThread();
System.out.println(t.toString());
System.out.println(t.getThreadGroup().toString());
//long l=Long.MAX_VALUE;
for(long i=0;i<Long.MAX_VALUE;i++){
MyClass my=new MyClass();
if(i%10000==0) Thread.sleep(1000);
}
}}
class MyClass {
protected void finalize() throws Throwable{
super.finalize();
Thread t=Thread.currentThread();
System.out.println(t.toString());
System.out.println(t.getThreadGroup().toString());
}
}
所以通过在垃圾回收时来获得这个线程环境,也就是finalize方法是被GC线程调用的。
这个方法在子类MyClass被 protected void finalize() throws Throwable覆盖了