aspose file tools*
The moose likes Servlets and the fly likes Static and Singleton in Web Applications? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Static and Singleton in Web Applications?" Watch "Static and Singleton in Web Applications?" New topic
Author

Static and Singleton in Web Applications?

Edna Earhart
Greenhorn

Joined: Aug 18, 2008
Posts: 4
I am trying to get a better understanding of how static methods (common in util classes) and Singleton classes work in web applications. I understand that a Singleton class would only have one instance per jvm similarly with static methods, but how do these not become a bottleneck in web applications - as the way I am( maybe erroneously) thinking about it is for every client accessing they are bottlenecking on these static methods - I guess also I don't understand how the application server (JBoss in my case) handles threading and the like(when load becomes heavy for instance). Know what I mean? Any articles etc. explaining these concepts would be much appreciated? Thanks
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Edna,
Welcome to JavaRanch!

While there is only one copy of the object (singleton) or method (static), there isn't a lock. This means that multiple callers can be in the object/method at the same time. For more on this search for the word "threadsafe". That word will show you objects that allow multiple callers at the same time. (along with those that don't handle it properly at all.)

If you were using the synchronized keyword, you would have a bottleneck as then only one thread/caller could access at a time.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
wood burning stoves
 
subject: Static and Singleton in Web Applications?