本帖最后由 孙百鑫 于 2013-6-20 19:17 编辑
- class Single implements Runnable
- {
- int x=100;
- private static Single s=null;
- private Single()
- {
- while(true)
- {
- if(x>0)
- System.out.println(Thread.currentThread().getName()+" 输出 "+x--);
- }
- }
- public static Single getInstance()
- {
- if(s==null)
- {
- synchronized(Single.class)
- {
- if (s==null)
- {
- s=new Single();
- }
- }
- }
- return s;
- }
- public void run()
- {
- getInstance();
- }
- }
- class SingleDemo
- {
- public static void main(String[] args)
- {
- Thread t1=new Thread(Single.getInstance());
- Thread t2=new Thread(Single.getInstance());
- t1.start();
- t2.start();
- }
- }
复制代码 请问各位我这个多线程程序中为什么只输出主线程,而没有我创建的线程呢?按说运行run方法时是会输出我创建的线程的啊?
|