Java Doc for StaticBucketMap.java in  » Library » Apache-common-Collections » org » apache » commons » collections » 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 Collections » org.apache.commons.collections 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.collections.StaticBucketMap

StaticBucketMap
final public class StaticBucketMap implements Map(Code)
A StaticBucketMap is an efficient, thread-safe implementation of java.util.Map that performs well in in a highly thread-contentious environment. The map supports very efficient StaticBucketMap.get(Object) get , StaticBucketMap.put(Object,Object) put , StaticBucketMap.remove(Object) remove and StaticBucketMap.containsKey(Object) containsKey operations, assuming (approximate) uniform hashing and that the number of entries does not exceed the number of buckets. If the number of entries exceeds the number of buckets or if the hash codes of the objects are not uniformly distributed, these operations have a worst case scenario that is proportional to the number of elements in the map (O(n)).

Each bucket in the hash table has its own monitor, so two threads can safely operate on the map at the same time, often without incurring any monitor contention. This means that you don't have to wrap instances of this class with java.util.Collections.synchronizedMap(Map) ; instances are already thread-safe. Unfortunately, however, this means that this map implementation behaves in ways you may find disconcerting. Bulk operations, such as StaticBucketMap.putAll(Map) putAll or the Collection.retainAll(Collection) retainAll operation in collection views, are not atomic. If two threads are simultaneously executing

 staticBucketMapInstance.putAll(map);
 
and
 staticBucketMapInstance.entrySet().removeAll(map.entrySet());
 
then the results are generally random. Those two statement could cancel each other out, leaving staticBucketMapInstance essentially unchanged, or they could leave some random subset of map in staticBucketMapInstance.

Also, much like an encyclopedia, the results of StaticBucketMap.size() and StaticBucketMap.isEmpty() are out-of-date as soon as they are produced.

The iterators returned by the collection views of this class are not fail-fast. They will never raise a java.util.ConcurrentModificationException . Keys and values added to the map after the iterator is created do not necessarily appear during iteration. Similarly, the iterator does not necessarily fail to return keys and values that were removed after the iterator was created.

Finally, unlike java.util.HashMap -style implementations, this class never rehashes the map. The number of buckets is fixed at construction time and never altered. Performance may degrade if you do not allocate enough buckets upfront.

The StaticBucketMap.atomic(Runnable) method is provided to allow atomic iterations and bulk operations; however, overuse of StaticBucketMap.atomic(Runnable) atomic will basically result in a map that's slower than an ordinary synchronized java.util.HashMap . Use this class if you do not require reliable bulk operations and iterations, or if you can make your own guarantees about how bulk operations will affect the map.


since:
   Commons Collections 2.1
version:
   $Revision: 348273 $ $Date: 2005-11-22 22:24:25 +0000 (Tue, 22 Nov 2005) $
author:
   Berin Loritsch
author:
   Gerhard Froehlich
author:
   Michael A. Smith
author:
   Paul Jack
author:
   Leo Sutic
author:
   Janek Bogucki
author:
   Kazuya Ujihara




Constructor Summary
public  StaticBucketMap()
     Initializes the map with the default number of buckets (255).
public  StaticBucketMap(int numBuckets)
     Initializes the map with a specified number of buckets.

Method Summary
public  voidatomic(Runnable r)
     Prevents any operations from occurring on this map while the given Runnable executes.
final public  voidclear()
     Implements Map.clear .
public  booleancontainsKey(Object key)
     Implements Map.containsKey(Object) .
public  booleancontainsValue(Object value)
     Implements Map.containsValue(Object) .
public  SetentrySet()
     Implements Map.entrySet .
final public  booleanequals(Object obj)
     Implements Map.equals(Object) .
public  Objectget(Object key)
     Implements Map.get(Object) .
final public  inthashCode()
     Implements Map.hashCode .
final public  booleanisEmpty()
     Implements Map.isEmpty .
public  SetkeySet()
     Implements Map.keySet .
public  Objectput(Object key, Object value)
     Implements Map.put(ObjectObject) .
public  voidputAll(Map other)
     Implements Map.putAll(Map) .
public  Objectremove(Object key)
     Implements Map.remove(Object) .
public  intsize()
     Implements Map.size .
public  Collectionvalues()
     Implements Map.values .


Constructor Detail
StaticBucketMap
public StaticBucketMap()(Code)
Initializes the map with the default number of buckets (255).



StaticBucketMap
public StaticBucketMap(int numBuckets)(Code)
Initializes the map with a specified number of buckets. The number of buckets is never below 17, and is always an odd number (StaticBucketMap ensures this). The number of buckets is inversely proportional to the chances for thread contention. The fewer buckets, the more chances for thread contention. The more buckets the fewer chances for thread contention.
Parameters:
  numBuckets - the number of buckets for this map




Method Detail
atomic
public void atomic(Runnable r)(Code)
Prevents any operations from occurring on this map while the given Runnable executes. This method can be used, for instance, to execute a bulk operation atomically:
 staticBucketMapInstance.atomic(new Runnable() {
 public void run() {
 staticBucketMapInstance.putAll(map);
 }
 });
 
It can also be used if you need a reliable iterator:
 staticBucketMapInstance.atomic(new Runnable() {
 public void run() {
 Iterator iterator = staticBucketMapInstance.iterator();
 while (iterator.hasNext()) {
 foo(iterator.next();
 }
 }
 });
 
Implementation note: This method requires a lot of time and a ton of stack space. Essentially a recursive algorithm is used to enter each bucket's monitor. If you have twenty thousand buckets in your map, then the recursive method will be invoked twenty thousand times. You have been warned.
Parameters:
  r - the code to execute atomically



clear
final public void clear()(Code)
Implements Map.clear .



containsKey
public boolean containsKey(Object key)(Code)
Implements Map.containsKey(Object) .



containsValue
public boolean containsValue(Object value)(Code)
Implements Map.containsValue(Object) .



entrySet
public Set entrySet()(Code)
Implements Map.entrySet .



equals
final public boolean equals(Object obj)(Code)
Implements Map.equals(Object) .



get
public Object get(Object key)(Code)
Implements Map.get(Object) .



hashCode
final public int hashCode()(Code)
Implements Map.hashCode .



isEmpty
final public boolean isEmpty()(Code)
Implements Map.isEmpty .



keySet
public Set keySet()(Code)
Implements Map.keySet .



put
public Object put(Object key, Object value)(Code)
Implements Map.put(ObjectObject) .



putAll
public void putAll(Map other)(Code)
Implements Map.putAll(Map) .



remove
public Object remove(Object key)(Code)
Implements Map.remove(Object) .



size
public int size()(Code)
Implements Map.size .



values
public Collection values()(Code)
Implements Map.values .



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.