Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2008
    Posts
    68
    Rep Power
    0

    Thumbs up How can we Use SoftReference in Java for better performance

    I have heard that with the use of SoftReference we can build faster and efficient cache.

    I have no clue how it can be done, We are trying to build a HashMap based cache, I am just thinking of utilizing SoftReference based cache to have memory efficient implementation.

    Can someone please suggest how I can do it?

    Any example code or links would be really helpful.

    Also let me know is it really worth doing ? Or a simple HashMap based cache is better to use?

    ____________________________________________
    Cooking is Fun

  2. #2
    kzvi.kzvi.1 is offline Member
    Join Date
    Oct 2008
    Location
    US
    Posts
    58
    Rep Power
    0

    Default

    SoftReference are good way to implement memory efficient cache as the Java Specification says that Garbage collector will clear all soft references before throwing OutofMemoryError.

    Code will definitely become more complex then a simple HashMap cache, so if you are going to build a really memory consuming cache then you can utilize a SoftReference based cache.

    Here is an example of [ Cache Using SoftReference ]

    There are more ways to implement reference queue clean up logic. May be other people on forum can also give input on the same.

    ____________________________________________
    Software Wiki
    Have fun....
    JAVA FAQs

Similar Threads

  1. Java Performance Ideas
    By developer321 in forum Advanced Java
    Replies: 4
    Last Post: 06-28-2008, 04:16 PM
  2. how to improve java performance
    By sunjavaboy in forum Advanced Java
    Replies: 6
    Last Post: 06-15-2008, 05:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •