当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

    摘要: http://www.11players.net/showtopic.asp?topic_id=138784&forum_id=24 ......
 ·有了解北京就医环境的人吗(    »显示摘要«
    摘要: 有了解北京就医环境的人吗?? 姐姐下月要生小孩,但是说现在就地治疗fd,不知道,哪家医院能够保证孕妇的安全呀 现在消息一片混乱,希望了解北京就医环境的人,给点提示,谢谢 ......


java Thread

class   MyThread   extends   Thread{  
  public   void   run(){  
  System.out.println("MyThread:   run()");  
  }  
  public   void   start(){  
  System.out.println("MyThread:   start()");  
  }  
  }  
  class   MyRunnable   implements   Runnable{  
  public   void   run(){  
  System.out.println("MyRunnable:   run()");  
  }  
  public   void   start(){  
  System.out.println("MyRunnable:   start()");  
  }  
  }  
  public   class   MyTest   {  
  public   static   void   main(String   args[]){  
  MyThread   myThread     =     new   MyThread();  
  MyRunnable   myRunnable   =   new   MyRunnable();  
  Thread   thread     =     new   Thread(myRunnable);  
  myThread.start();  
  thread.start();  
  }  
  }  
   
  为什么结果是  
  MyThread:   start()    
  MyRunnable:   run()????  
   
    Which   of   the   following   collection   classes   from   java.util   package   are   Thread   safe?  
  A.Vector  
  B.ArrayList     //与Vector类似,只是不同步  
  C.HashMap  
  D.Hashtable  
   
  为什么选A.D?

NO.1   作者: MyXin

Vector和Hashtable的许多方法都是同步的。故而线程安全!看他们的源码

NO.2   作者: geyf

因为Thread   thread     =     new   Thread(myRunnable);//实现了接口  
  所以  
  thread.start();时执行的是  
  public   void   run(){  
  System.out.println("MyRunnable:   run()");  
  }方法  
   
  另一个没有,只是调用了start()方法而已

NO.3   作者: wanglh2000

1)Thread   thread     =     new   Thread(myRunnable);相当于运行MyRunnable这个线程。  
  2)建议你看一看源代码,看了Vector,ArrayList,HashMap,Hashtable的具体实现你就明白了。


 ·实现发布/订阅只能用com+吗    »显示摘要«
    摘要: 我知道在c#下可以编码自己实现observer模式(发布、订阅模式),但是这样太复杂了,需要自己维护很多东西。据说.net下有这样的机制可以利用实现 但是找了半天好像只有利用com+才可以实现。请问我可以利用remoting或者webservice等其他手段实现吗?.net本身有这样的机制提供吗? 多谢了 ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE