空指针异常,通常是给不该赋null值的对象赋了null,改如下:
package Thread;
public class PrintStatic implements Runnable
{
public PrintStatic()
{
}
public static void main(String[] args)
{
Thread t1 = new Thread(new PrintStatic(),"t1");
t1.start();
Thread t2 = new Thread(new PrintStatic(),"t2");
t2.start();
System.out.println("Total Thread Count:"+Thread.activeCount());
Thread[] threads = new Thread[Thread.activeCount()];
Thread.enumerate(threads) ;
for(int i = 0 ; i< threads.length-1 ; i ++)
{
System.out.println("Thread Name :"+threads[i].getName());
} }
public void run()
{
try
{
Thread.sleep(1000);
}
catch(Exception e)
{
e.printStackTrace();
}
aMethod();
}
public void aMethod()
{
Thread.dumpStack();
}
}
package Thread;
public class PrintStatic implements Runnable
{
public PrintStatic()
{
}
public static void main(String[] args)
{
Thread t1 = new Thread(new PrintStatic(),"t1");
t1.start();
Thread t2 = new Thread(new PrintStatic(),"t2");
t2.start();
System.out.println("Total Thread Count:"+Thread.activeCount());
Thread[] threads = new Thread[Thread.activeCount()];
Thread.enumerate(threads) ;
for(int i = 0 ; i< threads.length-1 ; i ++)
{
System.out.println("Thread Name :"+threads[i].getName());
} }
public void run()
{
try
{
Thread.sleep(1000);
}
catch(Exception e)
{
e.printStackTrace();
}
aMethod();
}
public void aMethod()
{
Thread.dumpStack();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货