20-01-2010, 07:25 PM | #1 |
Administrator
|
servlet a singleton?
__________________
अब माई हिंदी फोरम, फेसबुक पर भी है. https://www.facebook.com/hindiforum |
21-01-2010, 06:14 AM | #2 |
Member
Join Date: Dec 2009
Posts: 50
Rep Power: 15 |
No servlets are not singleton..
The Servlet API does not restrict the creation of a particular Servlet class to a single instance, therefore it is not a Singleton. |
15-08-2010, 08:45 AM | #3 |
Junior Member
Join Date: Aug 2010
Posts: 6
Rep Power: 0 |
The Singleton's purpose is to control object creation, limiting the number to one but allowing the flexibility to create more objects if the situation changes. Since there is only one Singleton instance, any instance fields of a Singleton will occur only once per class, just like static fields.
Singletons often control access to resources such as database connections or sockets. For example, if you have a license for only one connection for your database or your JDBC driver has trouble with multithreading, the Singleton makes sure that only one connection is made or that only one thread can access the connection at a time. If you add database connections or use a JDBC driver that allows multithreading, the Singleton can be easily adjusted to allow more connections. Moreover, Singletons can be stateful; in this case, their role is to serve as a unique repository of state. If you are implementing a counter that needs to give out sequential and unique numbers (such as the machine that gives out numbers in the deli), the counter needs to be globally unique. The Singleton can hold the number and synchronize access; if later you want to hold counters in a database for persistence, you can change the private implementation of the Singleton without changing the interface. =============== monokinis Volunteer Abroad in Malawi |
Bookmarks |
|
|