Java Doc for ConcurrentHashMap.java in  » J2EE » wicket » wicket » util » concurrent » 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 » J2EE » wicket » wicket.util.concurrent 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.util.AbstractMap
      wicket.util.concurrent.ConcurrentHashMap

ConcurrentHashMap
public class ConcurrentHashMap extends AbstractMap implements Map,Cloneable,Serializable(Code)
A version of Hashtable supporting concurrency for both retrievals and updates:
Retrievals
Retrievals may overlap updates. (This is the same policy as ConcurrentReaderHashMap.) Successful retrievals using get(key) and containsKey(key) usually run without locking. Unsuccessful retrievals (i.e., when the key is not present) do involve brief synchronization (locking). Because retrieval operations can ordinarily overlap with update operations (i.e., put, remove, and their derivatives), retrievals can only be guaranteed to return the results of the most recently completed operations holding upon their onset. Retrieval operations may or may not return results reflecting in-progress writing operations. However, the retrieval operations do always return consistent results -- either those holding before any single modification or after it, but never a nonsense result. For aggregate operations such as putAll and clear, concurrent reads may reflect insertion or removal of only some entries.

Iterators and Enumerations (i.e., those returned by keySet().iterator(), entrySet().iterator(), values().iterator(), keys(), and elements()) return elements reflecting the state of the hash table at some point at or since the creation of the iterator/enumeration. They will return at most one instance of each element (via next()/nextElement()), but might or might not reflect puts and removes that have been processed since they were created. They do not throw ConcurrentModificationException. However, these iterators are designed to be used by only one thread at a time. Passing an iterator across multiple threads may lead to unpredictable results if the table is being concurrently modified.

Updates
This class supports a hard-wired preset concurrency level of 32. This allows a maximum of 32 put and/or remove operations to proceed concurrently. This level is an upper bound on concurrency, not a guarantee, since it interacts with how well-strewn elements are across bins of the table. (The preset value in part reflects the fact that even on large multiprocessors, factors other than synchronization tend to be bottlenecks when more than 32 threads concurrently attempt updates.) Additionally, operations triggering internal resizing and clearing do not execute concurrently with any operation.

There is NOT any support for locking the entire table to prevent updates. This makes it imposssible, for example, to add an element only if it is not already present, since another thread may be in the process of doing the same thing. If you need such capabilities, consider instead using the ConcurrentReaderHashMap class.

Because of how concurrency control is split up, the size() and isEmpty() methods require accumulations across 32 control segments, and so might be slightly slower than you expect.

This class may be used as a direct replacement for java.util.Hashtable in any application that does not rely on the ability to lock the entire table to prevent updates. As of this writing, it performs much faster than Hashtable in typical multi-threaded applications with multiple readers and writers. Like Hashtable but unlike java.util.HashMap, this class does NOT allow null to be used as a key or value.

Implementation note: A slightly faster implementation of this class will be possible once planned Java Memory Model revisions are in place.

[ Introduction to this package. ]


Inner Class :final protected static class Segment implements Serializable
Inner Class :protected static class Entry implements Map.Entry
Inner Class :protected class HashIterator implements Iterator,Enumeration
Inner Class :protected class KeyIterator extends HashIterator
Inner Class :protected class ValueIterator extends HashIterator

Field Summary
final protected static  intCONCURRENCY_LEVEL
     The number of concurrency control segments.
final public static  intDEFAULT_INITIAL_CAPACITY
     The default initial number of table slots for this table (32).
final public static  floatDEFAULT_LOAD_FACTOR
     The default load factor for this table (0.75) Used when not otherwise specified in constructor.
final protected static  intSEGMENT_MASK
    
protected transient  SetentrySet
    
protected transient  SetkeySet
    
final protected  floatloadFactor
     The load factor for the hash table.
final protected  Segment[]segments
     The array of concurrency control segments.
protected transient  Entry[]table
     The hash table data.
protected  intthreshold
     Per-segment resize threshold.
protected transient  Collectionvalues
    
protected transient volatile  intvotesForResize
     Number of segments voting for resize.

Constructor Summary
public  ConcurrentHashMap(int initialCapacity, float loadFactor)
     Constructs a new, empty map with the specified initial capacity and the specified load factor.
Parameters:
  initialCapacity - the initial capacity.
public  ConcurrentHashMap(int initialCapacity)
     Constructs a new, empty map with the specified initial capacity and default load factor.
public  ConcurrentHashMap()
     Constructs a new, empty map with a default initial capacity and default load factor.
public  ConcurrentHashMap(Map t)
     Constructs a new map with the same mappings as the given map.

Method Summary
protected static  intbitcount(int w)
     Return the number of set bits in w.
public  voidclear()
     Removes all mappings from this map.
public  Objectclone()
     Returns a shallow copy of this ConcurrentHashMap instance: the keys and values themselves are not cloned.
public  booleancontains(Object value)
     Tests if some key maps into the specified value in this table.
public  booleancontainsKey(Object key)
     Tests if the specified object is a key in this table.
Parameters:
  key - possible key.
public  booleancontainsValue(Object value)
     Returns true if this map maps one or more keys to the specified value.
public  Enumerationelements()
     Returns an enumeration of the values in this table.
public  SetentrySet()
     Returns a collection view of the mappings contained in this map.
protected  booleaneq(Object x, Object y)
     Check for equality of non-null references x and y.
public  Objectget(Object key)
     Returns the value to which the specified key is mapped in this table.
Parameters:
  key - a key in the table.
protected static  inthash(Object x)
     Return hash code for Object x.
public  booleanisEmpty()
     Returns true if this map contains no key-value mappings.
public  SetkeySet()
     Returns a set view of the keys contained in this map.
public  Enumerationkeys()
     Returns an enumeration of the keys in this table.
protected  Entry[]newTable(int capacity)
    
public  Objectput(Object key, Object value)
     Maps the specified key to the specified value in this table.
public  voidputAll(Map t)
     Copies all of the mappings from the specified map to this one.
protected  voidrehash()
     Rehashes the contents of this map into a new table with a larger capacity.
public  Objectremove(Object key)
     Removes the key (and its corresponding value) from this table.
protected  Objectremove(Object key, Object value)
     Removes the (key, value) pair from this table.
protected  voidresize(int index, Entry[] assumedTab)
     Gather all locks in order to call rehash, by recursing within synch blocks for each segment index.
Parameters:
  index - the current segment.
public  intsize()
     Returns the number of key-value mappings in this map.
public  Collectionvalues()
     Returns a collection view of the values contained in this map.

Field Detail
CONCURRENCY_LEVEL
final protected static int CONCURRENCY_LEVEL(Code)
The number of concurrency control segments. The value can be at most 32 since ints are used as bitsets over segments. Emprically, it doesn't seem to pay to decrease it either, so the value should be at least 32. In other words, do not redefine this :-)



DEFAULT_INITIAL_CAPACITY
final public static int DEFAULT_INITIAL_CAPACITY(Code)
The default initial number of table slots for this table (32). Used when not otherwise specified in constructor.



DEFAULT_LOAD_FACTOR
final public static float DEFAULT_LOAD_FACTOR(Code)
The default load factor for this table (0.75) Used when not otherwise specified in constructor.



SEGMENT_MASK
final protected static int SEGMENT_MASK(Code)
Mask value for indexing into segments



entrySet
protected transient Set entrySet(Code)



keySet
protected transient Set keySet(Code)



loadFactor
final protected float loadFactor(Code)
The load factor for the hash table.



segments
final protected Segment[] segments(Code)
The array of concurrency control segments.



table
protected transient Entry[] table(Code)
The hash table data.



threshold
protected int threshold(Code)
Per-segment resize threshold.



values
protected transient Collection values(Code)



votesForResize
protected transient volatile int votesForResize(Code)
Number of segments voting for resize. The table is doubled when 1/4 of the segments reach threshold. Volatile but updated without synch since this is just a heuristic.




Constructor Detail
ConcurrentHashMap
public ConcurrentHashMap(int initialCapacity, float loadFactor)(Code)
Constructs a new, empty map with the specified initial capacity and the specified load factor.
Parameters:
  initialCapacity - the initial capacity. The actual initial capacity is roundedto the nearest power of two.
Parameters:
  loadFactor - the load factor threshold, used to control resizing. Thisvalue is used in an approximate way: When at least a quarterof the segments of the table reach per-segment threshold, orone of the segments itself exceeds overall threshold, thetable is doubled. This will on average cause resizing when thetable-wide load factor is slightly less than the threshold. Ifyou'd like to avoid resizing, you can set this to aridiculously large value.
throws:
  IllegalArgumentException - if the load factor is nonpositive.



ConcurrentHashMap
public ConcurrentHashMap(int initialCapacity)(Code)
Constructs a new, empty map with the specified initial capacity and default load factor.
Parameters:
  initialCapacity - the initial capacity of the ConcurrentHashMap.
throws:
  IllegalArgumentException - if the initial maximum number of elements is less than zero.



ConcurrentHashMap
public ConcurrentHashMap()(Code)
Constructs a new, empty map with a default initial capacity and default load factor.



ConcurrentHashMap
public ConcurrentHashMap(Map t)(Code)
Constructs a new map with the same mappings as the given map. The map is created with a capacity of twice the number of mappings in the given map or 32 (whichever is greater), and a default load factor.
Parameters:
  t - map to copy




Method Detail
bitcount
protected static int bitcount(int w)(Code)
Return the number of set bits in w. For a derivation of this algorithm, see "Algorithms and data structures with applications to graphics and geometry", by Jurg Nievergelt and Klaus Hinrichs, Prentice Hall, 1993. See also notes by Torsten Sillke at http://www.mathematik.uni-bielefeld.de/~sillke/PROBLEMS/bitcount
Parameters:
  w - arg number of set bits



clear
public void clear()(Code)
Removes all mappings from this map.



clone
public Object clone()(Code)
Returns a shallow copy of this ConcurrentHashMap instance: the keys and values themselves are not cloned. a shallow copy of this map.



contains
public boolean contains(Object value)(Code)
Tests if some key maps into the specified value in this table. This operation is more expensive than the containsKey method.

Note that this method is identical in functionality to containsValue, (which is part of the Map interface in the collections framework).
Parameters:
  value - a value to search for. true if and only if some key maps to thevalue argument in this table as determined by theequals method; false otherwise.
exception:
  NullPointerException - if the value is null.
See Also:   ConcurrentHashMap.containsKey(Object)
See Also:   ConcurrentHashMap.containsValue(Object)
See Also:   Map




containsKey
public boolean containsKey(Object key)(Code)
Tests if the specified object is a key in this table.
Parameters:
  key - possible key. true if and only if the specified object is a keyin this table, as determined by the equals method;false otherwise.
exception:
  NullPointerException - if the key is null.
See Also:   ConcurrentHashMap.contains(Object)



containsValue
public boolean containsValue(Object value)(Code)
Returns true if this map maps one or more keys to the specified value. Note: This method requires a full internal traversal of the hash table, and so is much slower than method containsKey.
Parameters:
  value - value whose presence in this map is to be tested. true if this map maps one or more keys to thespecified value.
exception:
  NullPointerException - if the value is null.



elements
public Enumeration elements()(Code)
Returns an enumeration of the values in this table. Use the Enumeration methods on the returned object to fetch the elements sequentially. an enumeration of the values in this table.
See Also:   java.util.Enumeration
See Also:   ConcurrentHashMap.keys()
See Also:   ConcurrentHashMap.values()
See Also:   Map



entrySet
public Set entrySet()(Code)
Returns a collection view of the mappings contained in this map. Each element in the returned collection is a Map.Entry. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations. a collection view of the mappings contained in this map.



eq
protected boolean eq(Object x, Object y)(Code)
Check for equality of non-null references x and y.
Parameters:
  x - ref
Parameters:
  y - ref is equal



get
public Object get(Object key)(Code)
Returns the value to which the specified key is mapped in this table.
Parameters:
  key - a key in the table. the value to which the key is mapped in this table;null if the key is not mapped to any value in thistable.
exception:
  NullPointerException - if the key is null.
See Also:   ConcurrentHashMap.put(Object,Object)



hash
protected static int hash(Object x)(Code)
Return hash code for Object x. Since we are using power-of-two tables, it is worth the effort to improve hashcode via the same multiplicative scheme as used in IdentityHashMap.
Parameters:
  x - hash code



isEmpty
public boolean isEmpty()(Code)
Returns true if this map contains no key-value mappings. true if this map contains no key-value mappings.



keySet
public Set keySet()(Code)
Returns a set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. The set supports element removal, which removes the corresponding mapping from this map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations. a set view of the keys contained in this map.



keys
public Enumeration keys()(Code)
Returns an enumeration of the keys in this table. an enumeration of the keys in this table.
See Also:   Enumeration
See Also:   ConcurrentHashMap.elements()
See Also:   ConcurrentHashMap.keySet()
See Also:   Map



newTable
protected Entry[] newTable(int capacity)(Code)
Create table array and set the per-segment threshold *
Parameters:
  capacity - table array



put
public Object put(Object key, Object value)(Code)
Maps the specified key to the specified value in this table. Neither the key nor the value can be null. (Note that this policy is the same as for java.util.Hashtable, but unlike java.util.HashMap, which does accept nulls as valid keys and values.)

The value can be retrieved by calling the get method with a key that is equal to the original key.
Parameters:
  key - the table key.
Parameters:
  value - the value. the previous value of the specified key in this table, ornull if it did not have one.
exception:
  NullPointerException - if the key or value is null.
See Also:   Object.equals(Object)
See Also:   ConcurrentHashMap.get(Object)




putAll
public void putAll(Map t)(Code)
Copies all of the mappings from the specified map to this one. These mappings replace any mappings that this map had for any of the keys currently in the specified Map.
Parameters:
  t - Mappings to be stored in this map.



rehash
protected void rehash()(Code)
Rehashes the contents of this map into a new table with a larger capacity.



remove
public Object remove(Object key)(Code)
Removes the key (and its corresponding value) from this table. This method does nothing if the key is not in the table.
Parameters:
  key - the key that needs to be removed. the value to which the key had been mapped in this table, ornull if the key did not have a mapping.
exception:
  NullPointerException - if the key is null.



remove
protected Object remove(Object key, Object value)(Code)
Removes the (key, value) pair from this table. This method does nothing if the key is not in the table, or if the key is associated with a different value. This method is needed by EntrySet.
Parameters:
  key - the key that needs to be removed.
Parameters:
  value - the associated value. If the value is null, it means "anyvalue". the value to which the key had been mapped in this table, ornull if the key did not have a mapping.
exception:
  NullPointerException - if the key is null.



resize
protected void resize(int index, Entry[] assumedTab)(Code)
Gather all locks in order to call rehash, by recursing within synch blocks for each segment index.
Parameters:
  index - the current segment. initially call value must be 0
Parameters:
  assumedTab - the state of table on first call to resize. If this changes onany call, the attempt is aborted because the table has alreadybeen resized by another thread.



size
public int size()(Code)
Returns the number of key-value mappings in this map. the number of key-value mappings in this map.



values
public Collection values()(Code)
Returns a collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. The collection supports element removal, which removes the corresponding mapping from this map, via the Iterator.remove, Collection.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations. a collection view of the values contained in this map.



Methods inherited from java.util.AbstractMap
public void clear()(Code)(Java Doc)
protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean containsKey(Object key)(Code)(Java Doc)
public boolean containsValue(Object value)(Code)(Java Doc)
abstract public Set<Entry<K, V>> entrySet()(Code)(Java Doc)
public boolean equals(Object o)(Code)(Java Doc)
public V get(Object key)(Code)(Java Doc)
public int hashCode()(Code)(Java Doc)
public boolean isEmpty()(Code)(Java Doc)
public Set<K> keySet()(Code)(Java Doc)
public V put(K key, V value)(Code)(Java Doc)
public void putAll(Map<? extends K, ? extends V> m)(Code)(Java Doc)
public V remove(Object key)(Code)(Java Doc)
public int size()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
public Collection<V> values()(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(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.