×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

java.lang.ref.WeekReference represents a reference which will be held for one week before being finalized by the garbage collector...

Just kidding with jabber's typo.
java.lang.ref package contains classes coping with the garbage collector.
java.lang.ref.Reference refers some types of indirect reference to a referent.
the subclasses of java.lang.ref.Reference interact with the garbage collector in different ways.
java.lang.ref.WeakReference is one of the three subclasses, it does NOT prevent that refent object from being finalized by the garbage collector. the garbage collector will clear the WeakreRerence if the garbage collector finds no more direct references..

WeakReference is used by java.util.WeakHashMap. WeakHashMap is useful if u want to attach additional information to an object but don't need it beprotected.
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / Jabber's java questions...
    One of my friends complained that we pay too much attention to the
    "trivial things" and wished us to discuss some "advanced" topics.
    To respond, I asked some questions here. Hope people can contribute ideas and thoughts.

    1) What is java.lang.ThreadLocal for?
    2) There is a package called java.lang.ref, under which there are a few classes and references, for exapmle, java.lanag.ref.WeekRefernce.
    What is this for?
    3) In Enterprise JavaBeans API, the getEnvironment() method of javax.ejb.EJBObject jas been deprecated. How the similar functionality is
    implemented in EJB API now?

    Thanks for contributions.
    • I couldn't find the getEnvironment() in javax.ejb.EJBObject.
      Dear Jabber,
      There is a same methed in the javax.ejb.EJBContext interface, I am not sure if you are talking about this one. It is deprecated. The same effect is achieved through JNDI naming context java:complenv .
      • It is exactly what you meant. Sorry for my mistakes. It is nice to see your correcting it. Thanks a lot.
    • java.lang.ThreadLocal provides a solution for the dilemma of static and nonstatic fields.
      When u declare a static field, there is only one value of the field for all objects, when u declare a non-static instance, every object has its own copy of this variable.. If u declare static filed to hold a ThreadLocal, it can holds a different value for each thread. Objects running in the same thread can get the identical value by calling get() while those running in different threads get different value..
    • java.lang.ref.WeekReference represents a reference which will be held for one week before being finalized by the garbage collector...
      Just kidding with jabber's typo.
      java.lang.ref package contains classes coping with the garbage collector.
      java.lang.ref.Reference refers some types of indirect reference to a referent.
      the subclasses of java.lang.ref.Reference interact with the garbage collector in different ways.
      java.lang.ref.WeakReference is one of the three subclasses, it does NOT prevent that refent object from being finalized by the garbage collector. the garbage collector will clear the WeakreRerence if the garbage collector finds no more direct references..

      WeakReference is used by java.util.WeakHashMap. WeakHashMap is useful if u want to attach additional information to an object but don't need it beprotected.