• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Final class and loading

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have a final class with all static methods and no instance varibles in it. I need this class in "Application Scope". Do I need to instatiate it some where( if so where) or JVM Loads it automatically. (When I say final class with all static methods, you can think it being very similar to Math class)

Thanks,
P Ingle
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's the problem with static classes such as Math, there is no real object to put into "application scope." That's why Jakarta Commons BeanUtils went to a more bean-like approach with its classes like BeanUtils and PropertyUtils.
 
P. Ingle
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
being a newbie to J2EE and whole Jacarta Apachi project I have to ask - what would that approach be?

Thanks,
P Ingle
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The static methods delegate to an instance method...

 
P. Ingle
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interesting. How does it behave under Heavy Loads - If I had to use this pattern to implement Class that hands out database connactions or for DAOFactory in high traffic web app, would this be a bottleneck?

Thanks,
P. Ingle
---------------------------
Questions, Questions and more Questions.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it doesn't cause any performance bottlenecks, but it's also not necessary to load a class. The class will simply be loaded when needed, at least before the first static method is called.

The solution shown by James is interesting when you want to change the behaviour at runtime - it's basically a variation of the Strategy pattern, as far as I can tell.
reply
    Bookmark Topic Watch Topic
  • New Topic