File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Static and Singleton in Web Applications?

Edna Earhart

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
author & internet detective

Joined: May 26, 2003
Posts: 33102

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Static and Singleton in Web Applications?
It's not a secret anymore!