Singleton? Don't want to keep reading database

Hi there,
I have a java web application, when it starts up I want it to load some information into a singleton so that all requests for this information come from memory not via a database call. The information will change very infrequently but I don't want to hard-code it (I guess I could use a property file). Anyway if I use a singleton will it not be garbage collected as soon as no other objects reference it? If it's garbage collected then the next time some accesses it another database call with be made and I don't want that to happen. I want this object to reside in memory always (it's not large so the hit is not that great). The singleton will basically hold a Vector of "objects" and one of this "objects" attributes is another Vector. To populate it requires 3 trips to the database each time. I would prefer 3 trips up front upon application loading and then no more until a restart occurs. Any suggestions?
Cheers, Max

The Singleton pattern is a fairly straightforward pattern. I have used it succesfully several times. Here is an example.
public class GetInfo {
  private static GetInfo singleton;
  private static Object dataSavedInMemory;
  //Prevent anyone from instantiating this object
  private GetInfo() {
  private static synchronized void initialize() {
    singleton = new GetInfo();
    //One time database processing to save data in memory would go here
    dataSavedInMemory = new String("Hello World");  //just for illustration purposes
  public static GetInfo instance() {
    if (singleton == null)
      initialize();
    return singleton;
  public Object getData() {
    return dataSavedInMemory;
  //Example usage
  public static void main(String[] args) {
    //Get data saved in memory
    Object data = GetInfo.instance().getData();
    System.out.println(data);
    //or
    GetInfo inst = GetInfo.instance();
    Object data2 = inst.getData();
    System.out.println(data2);
}

Similar Messages

  • How do I delete tracks I have recorded and don't want to keep?

    How do I delete songs I have recorded and don't want to keep on garageband?

    Larska wrote:
    How do I delete songs I have recorded and don't want to keep on garageband?
    http://www.bulletsandbones.com/GB/GBFAQ.html#deletegbprojects
    (Let the page FULLY load. The link to your answer is at the top of your screen)

  • When I do a download, it is saved to a Binary File. Where are these files stored & how do you uninstall a program you don't want to keep ?

    I use firefox, when I download a file from another website, there is a pop-up that shows the name of the download, which shows it is saved to a binary file, (don't know what a binary file is) but my question is where are the binary files stored on my computer & if I can uninstall it if I don't want to keep it.

    read basic about svchost:
    [http://support.microsoft.com/kb/314056/en-us A description of Svchost.exe in Windows XP Professional Edition]
    find svchost services:
    [http://webcache.googleusercontent.com/search?q=cache:pa9PdGlHr0sJ:www.bleepingcomputer.com/tutorials/list-services-running-under-svchost.exe-process/+what+is+svchost.exe&cd=12&hl=el&ct=clnk&gl=gr a way how to determine what services are running under a SVCHOST.EXE process]
    One Temporary Solution is to disable the Windows Automatic Update service:
    http://ask-leo.com/how_do_i_fix_this_high_cpu_usage_svchost_virus_or_whatever_it_is.html
    (no '''it is not''' a virus)
    (works for me)
    thank you
    Please mark "Solved" the answer that really solve the problem, to help others with a similar problem.

  • I just purchased the new Nokia windows phone.  How do I delete an app that I installed but really don't want to keep?

    I just purchased the new Nokia windows phone.  How do I delete an app that I installed but don't want to keep?

    You are welcome! I played with the 928 in a Verizon store and really liked it. Besides the great camera and Nokia Maps, I'd be pretty excited about Nokia Music, too. As I understand it, this free app lets you create playlists from its entire music library, which can be stored on your device to listen to any time.
    There are a few members on the WP board who are really knowledgeable about Nokia and WP, so let us know if you have more questions.

  • I downloaded the free upgrade for OS X Mavericks can you delete a download before installation ?  i don't want it after reading reviews.

    i downloaded the free upgrade for OS X Mavericks, can i  delete this download before installation ?  i don't want it after reading reviews.

    Yes, it's in your Applications folder and is called "Install OS X". Make sure to empty your trash afterwards to clear the space.
    Matt

  • Is it possible to save the iTunes icon on my computer to a USB stick and deleting the icon from the computer? I don't want to keep backing my iPod up on my computer

    I Don't want to keep backing up my iPod on my computer and using the memory and I wanted to save everything on a USB stick? Is it possible?

    Yes
    To move the library:
    iTunes for Windows: Moving your iTunes Media folder - Apple Support
    iTunes for Mac: Moving your iTunes Media folder - Apple Support

  • How do I remove photos from my iPhoto trash? I don't want to keep these pictures.

    I have a large number of photos that I really don't want to keep anymore.
    They are just taking up space on my computer.
    They are in the trash now, but I don't even want them there.

    Yes and then you'll have to empty the Trash bin in the Dock. 
    To get all of the photos out of the iPhoto Trash and easily have access to them for deleting in small groups do this:
    1 - select all of the photos in the Trash bin and drag onto the Album title in the left pane to create a new album with all of the photos.
    2 - go back to the Trash bin, select all of the photos and drag them onto the Events icon in the left hand pane to move them back to their original events.
    3 - go the the new album, select about 100 at a time and use the Command+Option+Delete key combination to move them to the iPhoto Trash bin.
    4 - empty the iPhoto Trash bin.
    5 - repeat steps 3 and 4 until all photos have been deleted.
    OT

  • HT5772 How do I delete podcast episodes that I don't want to keep without having them stay in my List view in iTunes and clog it up?  I have some episodes that I've listened to that I want to keep, but others I want to delete.

    Using iTunes on my MacBookPro, I find that when I want to delete selected podcast eisodes, they still stay in my List view with the cloud symbol next to them. I don't want them in my List view. I want them gone. I don't want to download them ever again. I do keep some episodes so I don't want to do the draconian thing and delete all podcast episodes once I've heard them. The other problem I have with trying to delete episodes is that some podcasts then have the same episodes pop back up as though I haven't listened to them. I've deleted a bunch of Science Friday episodes only to have them download again ready to hear. Not only that, but some episodes will finish playing or stop playing in the middle of an episode and a random podcast will start playing. Think! does that. GAH!!
    Does anyone know a workaround? The same nonsense happens in any iTunes view I try.
    <Edited by Host>

    You can delete photos from individual albums but not from the camera roll.  If you try to delete a photo from camera roll it will be deleted from all other albums ("locations") that contain the photo.  This is because the actual photo is in the camera roll (the albums only contain links to the photo in camera roll, not the actual photo).

  • How do I get Firefox/mozilla to stop "not allowing a page to change" I don't want to keep having to hit allow each time Thanks john

    On going to a new item on say news page a bar opens like in windows and reads Firefox has prevented this page from opening. then farther along the bar there is an allow button. I don't want to have to click each time. Thanks. john

    See:
    *Firefox/Tools > Options/Preferences > Advanced > General : Accessibility : [ ] "Warn me when web sites try to redirect or reload the page"
    The setting in "Tools > Options > Advanced > General" is meant as an accessibility feature, as you can see by the label of that section, so that people with disabilities or people who use screen readers do not get confused and is not meant as a safety protection to stop redirecting.
    See also:
    *https://support.mozilla.org/kb/settings-network-updates-and-encryption#w_general-tab
    *http://kb.mozillazine.org/accessibility.blockautorefresh
    *http://kb.mozillazine.org/Accessibility_features_of_Firefox

  • How do I restore my MacBook Pro running Lion to factory settings? I don't want to keep anything on the hard drive.

    I am running Lion and know how to get to my Mac OS X Utilities but I cannot figure out how to do a full factory setting restart like I have done the past with the OS disks. Any help would be great. Thanks.

    Use disk utility to format your hard drive then reinstall Mac OS X 10.7.2 (Lion) on to the hard drive. 

  • I have a iPad 16GB 4G ,when I delete videos or music the 'other'  increases by the same amount I just deleted.I don't want to keep restoring it and resetting it ... any other solutions?

    If I delete a 1.6Gb video, the 'other' increases by 1.6Gb.How do I fix this permanently?

    Sounds like you're trying sync different iTunes libraries on different computers.  You can only sync with one at any particular time.  If you sync with one and try to do so on another the second will want to delete everything form the first.  Can't think of any other reason why what you are doing should be a problem.

  • My iphone was stolen. is there a way to unsubscribe to a paying app? i don't want to keep paying for the app that i cant even use.

    itunes is still charging me for the app that i installed on my phone. i want to unsubscribe. is there a way?

    See the "Re-downloading In-App Purchases" section of this support article:
    http://support.apple.com/kb/HT4009
    Regards.

  • Are throwing the baby out with the bath water again?  Looks like I am losing the services I use, for crap I don't want to keep my eMail.

    Still mifed from losing all the time I put into Homepage.

    What has "homepage" to do with icloud ?
    it was a feature of MobileMe but is no feature in iCloud.Apple sees this sort of service as obsolete. You can use "homepage" hosting at Apple until next year.
    Just look for other hosters. iWeb will work in Lion, so not a problem at all.  You only need to move your created sites over per FTP to 3rd party companies that will host it for you. No drama.

  • Don't want AIR with Reader

    Has anybody been able to perform an installion of Reader 9.1 WITHOUT Air? I have the distribution copy of Reader and I can't figure out how to do it. I've even deleted the related AIR files in the setup directory but it STILL installs.
    I've tried using both ORCA and the Customization Wizard but neither was any help.

    I used the smaller executable. I have no idea what the large executable includes. It's twice the size!
    After I installed the executable, I go to c:\Program Files\Adobe\Reader 9.0\Setup Files
    I use the files in that directory to distribute on my network.

  • I am having difficulty downloading APPS in my IPAD2. iCloud keeps on reinstalling APPS. And about iTunes, do I have to keep the APPS I downloaded through iTunes? Because I only have a Mac Air 11 64G, so I don't want to back up my iPad apps in the Mac.

    Help? I keep on moving in circles. If I download the app through itunes and i go online with the ipad, icloud reinstalls the apps. Then if I download apps with the ipad and I plug it into the Mac, iTunes is forcing me to copy the purchases I made on the iPad to my iTunes. I don't want to keep too many files on the Mac, so I remove them from the iTunes, and if iTunes suddenly decides to force me to synce, I lose a lot of other Apps that I didn't even download using iTunes. I am very confused. How do I do this manually? I don't want to back up everything in the laptop because it's memory is very limited.

    Did you ever resolve the iCloud problem.I am in the same position and its driving me mad!!! If you have a link to an solution I would appreciate it.

Maybe you are looking for