to mhw1010() 那是你不看清楚书的问题!Servlet一直都是单实例的,无论实现SingleThreadModel与否。SingleThreadModel的意思是指该Servlet永远只能被一线程独占访问,也就是后续的请求必须等待前面的所有用户访问完后才能进入方法。读死书是没有用的,书上不一定都正确,必须实践才能出真知!
to ChDw(米) ( ) ------------------------ 下面这段是servlet api对SingleThreadModel的注释,servlet容器既然可以产生单个实例,当然可以产生多个,可能对实现该接口的并不一定会有多个实例,但是servlet只存在一份实例是不对的,注意下面用的instances复数!If a servlet implements this interface, you are guaranteed that no two threads will execute concurrently in the servlet's service method. The servlet container can make this guarantee by synchronizing access to a single instance of the servlet, or by maintaining a pool of servlet instances and dispatching each new request to a free servlet.
楼上的不要误导到人,servlet并非只能有一个实例,有一个标示接口SingleThreadModel,在声明servlet时实现这个接口的就代表你的servlet类是单线成的,跟servlet相关的书上都有提到单线成模式下servlet实现数据库连接池的问题!
------------------------
下面这段是servlet api对SingleThreadModel的注释,servlet容器既然可以产生单个实例,当然可以产生多个,可能对实现该接口的并不一定会有多个实例,但是servlet只存在一份实例是不对的,注意下面用的instances复数!If a servlet implements this interface, you are guaranteed that no two threads will execute concurrently in the servlet's service method. The servlet container can make this guarantee by synchronizing access to a single instance of the servlet, or by maintaining a pool of servlet instances and dispatching each new request to a free servlet.
找到一篇关于这方面的好文章,共享出来:
http://www.oreilly.com/catalog/jservlet/chapter/ch03.html