Java Doc for WeakHashtable.java in  » Library » apache-common-Logging » org » apache » commons » logging » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » apache common Logging » org.apache.commons.logging.impl 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.util.Hashtable
   org.apache.commons.logging.impl.WeakHashtable

WeakHashtable
final public class WeakHashtable extends Hashtable (Code)

Implementation of Hashtable that uses WeakReference's to hold its keys thus allowing them to be reclaimed by the garbage collector. The associated values are retained using strong references.

This class follows the symantics of Hashtable as closely as possible. It therefore does not accept null values or keys.

Note: This is not intended to be a general purpose hash table replacement. This implementation is also tuned towards a particular purpose: for use as a replacement for Hashtable in LogFactory. This application requires good liveliness for get and put. Various tradeoffs have been made with this in mind.

Usage: typical use case is as a drop-in replacement for the Hashtable used in LogFactory for J2EE enviroments running 1.3+ JVMs. Use of this class in most cases (see below) will allow classloaders to be collected by the garbage collector without the need to call org.apache.commons.logging.LogFactory.release(ClassLoader) LogFactory.release(ClassLoader) .

org.apache.commons.logging.LogFactory checks whether this class can be supported by the current JVM, and if so then uses it to store references to the LogFactory implementationd it loads (rather than using a standard Hashtable instance). Having this class used instead of Hashtable solves certain issues related to dynamic reloading of applications in J2EE-style environments. However this class requires java 1.3 or later (due to its use of java.lang.ref.WeakReference and associates). And by the way, this extends Hashtable rather than HashMap for backwards compatibility reasons. See the documentation for method LogFactory.createFactoryStore for more details.

The reason all this is necessary is due to a issue which arises during hot deploy in a J2EE-like containers. Each component running in the container owns one or more classloaders; when the component loads a LogFactory instance via the component classloader a reference to it gets stored in the static LogFactory.factories member, keyed by the component's classloader so different components don't stomp on each other. When the component is later unloaded, the container sets the component's classloader to null with the intent that all the component's classes get garbage-collected. However there's still a reference to the component's classloader from a key in the "global" LogFactory's factories member! If LogFactory.release() is called whenever component is unloaded, the classloaders will be correctly garbage collected; this should be done by any container that bundles commons-logging by default. However, holding the classloader references weakly ensures that the classloader will be garbage collected without the container performing this step.

Limitations: There is still one (unusual) scenario in which a component will not be correctly unloaded without an explicit release. Though weak references are used for its keys, it is necessary to use strong references for its values.

If the abstract class LogFactory is loaded by the container classloader but a subclass of LogFactory [LogFactory1] is loaded by the component's classloader and an instance stored in the static map associated with the base LogFactory class, then there is a strong reference from the LogFactory class to the LogFactory1 instance (as normal) and a strong reference from the LogFactory1 instance to the component classloader via getClass().getClassLoader(). This chain of references will prevent collection of the child classloader.

Such a situation occurs when the commons-logging.jar is loaded by a parent classloader (e.g. a server level classloader in a servlet container) and a custom LogFactory implementation is loaded by a child classloader (e.g. a web app classloader).

To avoid this scenario, ensure that any custom LogFactory subclass is loaded by the same classloader as the base LogFactory. Creating custom LogFactory subclasses is, however, rare. The standard LogFactoryImpl class should be sufficient for most or all users.


author:
   Brian Stansberry
since:
   1.1



Constructor Summary
public  WeakHashtable()
     Constructs a WeakHashtable with the Hashtable default capacity and load factor.

Method Summary
public  booleancontainsKey(Object key)
    
public  Enumerationelements()
    
public  SetentrySet()
    
public  Objectget(Object key)
    
public  booleanisEmpty()
    
public  SetkeySet()
    
public  Enumerationkeys()
    
public  Objectput(Object key, Object value)
    
public  voidputAll(Map t)
    
protected  voidrehash()
    
public  Objectremove(Object key)
    
public  intsize()
    
public  StringtoString()
    
public  Collectionvalues()
    


Constructor Detail
WeakHashtable
public WeakHashtable()(Code)
Constructs a WeakHashtable with the Hashtable default capacity and load factor.




Method Detail
containsKey
public boolean containsKey(Object key)(Code)

See Also:   Hashtable



elements
public Enumeration elements()(Code)

See Also:   Hashtable



entrySet
public Set entrySet()(Code)

See Also:   Hashtable



get
public Object get(Object key)(Code)

See Also:   Hashtable



isEmpty
public boolean isEmpty()(Code)

See Also:   Hashtable



keySet
public Set keySet()(Code)

See Also:   Hashtable



keys
public Enumeration keys()(Code)

See Also:   Hashtable



put
public Object put(Object key, Object value)(Code)

See Also:   Hashtable



putAll
public void putAll(Map t)(Code)

See Also:   Hashtable



rehash
protected void rehash()(Code)

See Also:   Hashtable



remove
public Object remove(Object key)(Code)

See Also:   Hashtable



size
public int size()(Code)

See Also:   Hashtable



toString
public String toString()(Code)

See Also:   Hashtable



values
public Collection values()(Code)

See Also:   Hashtable



Methods inherited from java.util.Hashtable
public synchronized void clear()(Code)(Java Doc)
public synchronized Object clone()(Code)(Java Doc)
public synchronized boolean contains(Object value)(Code)(Java Doc)
public synchronized boolean containsKey(Object key)(Code)(Java Doc)
public boolean containsValue(Object value)(Code)(Java Doc)
public synchronized Enumeration<V> elements()(Code)(Java Doc)
public Set<Map.Entry<K, V>> entrySet()(Code)(Java Doc)
public synchronized boolean equals(Object o)(Code)(Java Doc)
public synchronized V get(Object key)(Code)(Java Doc)
public synchronized int hashCode()(Code)(Java Doc)
public synchronized boolean isEmpty()(Code)(Java Doc)
public Set<K> keySet()(Code)(Java Doc)
public synchronized Enumeration<K> keys()(Code)(Java Doc)
public synchronized V put(K key, V value)(Code)(Java Doc)
public synchronized void putAll(Map<? extends K, ? extends V> t)(Code)(Java Doc)
protected void rehash()(Code)(Java Doc)
public synchronized V remove(Object key)(Code)(Java Doc)
public synchronized int size()(Code)(Java Doc)
public synchronized String toString()(Code)(Java Doc)
public Collection<V> values()(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.