This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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


Win a copy of Building Microservices this week in the Design forum!
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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32507
    
214

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.


[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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Static and Singleton in Web Applications?
 
It's not a secret anymore!