多线程测试,内存溢出,为什么java没给我自动回收垃圾?
import java.util.Date;import java.util.Timer;import java.util.TimerTask;public class T { private static int count=0; /** * @param args */ public static void main(String[] args) { class MyTimerTask extends TimerTask{ @Override public void run() { count=(count+1)%2; System.out.println(Thread.currentThread().getName()+" count:"+count); new Timer().schedule(new MyTimerTask(), 0+count*2); } } TimerTask task=new MyTimerTask(); System.out.println("开始"); new Timer().schedule(task, 3000); while(true){ try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(" "+Thread.currentThread().getName()+" "+new Date().getSeconds()); } } }