ConcurrentHashMap VS. HashTable

Hi all,
I need to use a thread-safe map and am not sure if I can safely use java.util.concurrent.ConcurrentHashMap instead of HashTable w/o external synchronization. The Java docs says:
"A hash table supporting full concurrency of retrievals and adjustable expected concurrency for updates. This class obeys the same functional specification as Hashtable, and includes versions of methods corresponding to each method of Hashtable.
*+However, even though all operations are thread-safe, retrieval operations do+ +not+ +entail locking, and there is+ +not+ +any support for locking the entire table in a way that prevents all access. This class is fully interoperable with+ **+Hashtable+** +in programs that rely on its thread safety but not on its synchronization details.+*
*+Retrieval operations (including+ **+get+**+) generally do not block, so may overlap with update operations (including+ **+put+** +and+ **+remove+**+). Retrievals reflect the results of the most recently+ +completed+ +update operations holding upon their onset. For aggregate operations such as+ **+putAll+** +and+ **+clear+**+, concurrent retrievals may reflect insertion or removal of only some entries. Similarly, Iterators and Enumerations return elements reflecting the state of the hash table at some point at or since the creation of the iterator/enumeration+*.
They do +not+ throw [ConcurrentModificationException|http://java.sun.com/javase/6/docs/api/java/util/ConcurrentModificationExceptio
*+However, iterators are designed to be used by only one thread at a time.+*"
I do use iterators on my map; and it will be used by many threads at the same time; so does that mean I need to externally "synchronize" my map?
The parts in bold and italic made me not sure about using the ConcurrentHashMap...

JavaFunda wrote:
So can anybody give a example where we hashtable can not be replace by ConcusrrentHashMapPersonally, other than Peter's first suggestion, I can't think of a single one. I believe that EJP's post (other than line 3) was aimed at why you might prefer a HashMap ( not Hashtable) over CHM; and he's dead right.
Winston

Similar Messages

  • Error Involving EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap

    The JVM is crashing and I am getting the following error. I am having a hard time getting started figuring out why this is happening. I am not using this method directly and am having a hard time figuring out what is leading to this. In Eclipse when I use open type the ConcurrentReaderHashMap class does not show up. Does this mean the class is coming from the JVM jar files? I am using java.util.concurrent.ConcurrentHashMap. I am wondering if it is being called from ConcurrentHashMap? When I use the Eclipse open type with ConcurrentHashMap I get two classes java.util.concurrent.ConcurrentHashMap and edu.emory.mathcs.backport.java.util.concurrent from the jar apache-activemq-4.1.1.jar. If I am correct and ConcurrentReaderHashMap is being called from ConcurrentHashMap. How can I figure out which one? I am using activemq, so if it is being called from activemq, there is little I can do from my code without taking on looking at the source from activemq. If it is from java.util.concurrent.ConcurrentHashMap, I may have more direct control. The strange thing about this is from the java doc from ConcurrentHashMap, I get the impression that thread safe iterators is one of the benefits of using ConcurrentHashMap over HashTable or Collections.synchronizedMap. Is this wrong? Any ideas you can provide me would be greatly appreciated. Thanks in Advance! The contents of the hs_err_pid file appears below:
    # An unexpected error has been detected by Java Runtime Environment:
    # SIGSEGV (0xb) at pc=0xb642e40e, pid=10152, tid=2990115744
    # Java VM: Java HotSpot(TM) Client VM (1.6.0_03-b05 mixed mode, sharing)
    # Problematic frame:
    # J EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap$HashIterator.hasNext()Z
    # If you would like to submit a bug report, please visit:
    # http://java.sun.com/webapps/bugreport/crash.jsp
    --------------- T H R E A D ---------------
    Current thread (0x0813a800): JavaThread "DeployerRunnable Thread for dai-core" [_thread_in_Java, id=17757]
    siginfo:si_signo=11, si_errno=0, si_code=1, si_addr=0xc99afacf
    Registers:
    EAX=0x499afad0, EBX=0x86e6f328, ECX=0x443b6620, EDX=0x86e6f928
    ESP=0xb23972a0, EBP=0xb23972b8, ESI=0x499afad0, EDI=0x00000019
    EIP=0xb642e40e, CR2=0xc99afacf, EFLAGS=0x00210212
    Top of Stack: (sp=0xb23972a0)
    0xb23972a0: 443b6620 443b6620 b23972a8 86e6e4dc
    0xb23972b0: b23972d0 86e6ea28 b23972fc b5f2718d
    0xb23972c0: 00000000 b23972d0 86e6f910 b5f2718d
    0xb23972d0: 443b6620 00000009 498c47e0 b23972d4
    0xb23972e0: 8583aadb b239731c 858acf40 00000000
    0xb23972f0: 8583ade8 b23972d0 b239731c b2397348
    0xb2397300: b5f26edd 00000000 00000000 00000000
    0xb2397310: 00000000 443b6620 498c47e0 498c1010
    Instructions: (pc=0xb642e40e)
    0xb642e3fe: 66 90 8b 71 0c 83 fe 00 0f 84 67 00 00 00 3b 06
    0xb642e40e: 8b be ff ff ff 7f 83 ff 00 0f 85 a0 00 00 00 3b
    Stack: [0xb2348000,0xb2399000), sp=0xb23972a0, free space=316k
    Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
    J EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap$HashIterator.hasNext()Z
    j com.evermind.server.http.HttpApplication.destroyServlets()V+23
    j com.evermind.server.http.HttpApplication.destroy()V+182
    j com.evermind.server.http.HttpApplication.stopCleanUp(Ljava/util/List;)V+10
    j com.evermind.server.http.HttpApplication.componentStop(Ljava/util/List;)V+26
    j com.evermind.server.Application.doStop()V+208
    j com.evermind.server.Application.stop()V+8
    j oracle.oc4j.admin.management.mbeans.J2EEStateManageableObjectBase.stop()V+108
    j oracle.oc4j.admin.management.mbeans.J2EEApplication.stop()V+323
    v ~StubRoutines::call_stub
    V [libjvm.so+0x20bc6d]
    V [libjvm.so+0x30a828]
    V [libjvm.so+0x20bb00]
    V [libjvm.so+0x33156f]
    V [libjvm.so+0x333f6c]
    V [libjvm.so+0x277c28]
    C [libjava.so+0x15224] Java_sun_reflect_NativeMethodAccessorImpl_invoke0+0x34
    J sun.reflect.NativeMethodAccessorImpl.invoke0(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
    J sun.reflect.NativeMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
    J sun.reflect.DelegatingMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
    J java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
    j sun.reflect.misc.Trampoline.invoke(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+3
    j sun.reflect.GeneratedMethodAccessor40.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+40
    J sun.reflect.DelegatingMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
    J java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
    j sun.reflect.misc.MethodUtil.invoke(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+63
    j javax.management.modelmbean.RequiredModelMBean.invokeMethod(Ljava/lang/String;Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+11
    j javax.management.modelmbean.RequiredModelMBean.invoke(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;)Ljava/lang/Object;+657
    j oracle.oc4j.admin.jmx.server.mbeans.model.DefaultModelMBeanImpl.invoke(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;)Ljava/lang/Object;+65
    j com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Ljavax/management/ObjectName;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;)Ljava/lang/Object;+28
    j com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Ljavax/management/ObjectName;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;)Ljava/lang/Object;+13
    j oracle.oc4j.admin.jmx.server.state.ApplicationStateFilterMBeanServer.invoke(Ljavax/management/ObjectName;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;)Ljava/lang/Object;+14
    j oracle.oc4j.admin.internal.ApplicationDeployer.stopApplication()V+45
    j oracle.oc4j.admin.internal.ApplicationDeployer.doDeploy(Z)Z+93
    j oracle.oc4j.admin.internal.DeployerBase.execute(Z)Ljava/util/Map;+58
    j oracle.oc4j.admin.jmx.server.mbeans.deploy.OC4JDeployerRunnable.doRun()V+47
    j oracle.oc4j.admin.jmx.server.mbeans.deploy.DeployerRunnable.run()V+53
    J com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run()V
    j java.lang.Thread.run()V+11
    v ~StubRoutines::call_stub
    V [libjvm.so+0x20bc6d]
    V [libjvm.so+0x30a828]
    V [libjvm.so+0x20b580]
    V [libjvm.so+0x20b60d]
    V [libjvm.so+0x27b845]
    V [libjvm.so+0x384190]
    V [libjvm.so+0x30b719]
    C [libpthread.so.0+0x53cc]
    --------------- P R O C E S S ---------------
    Java Threads: ( => current thread )
    =>0x0813a800 JavaThread "DeployerRunnable Thread for dai-core" [_thread_in_Java, id=17757]
    0x08137c00 JavaThread "EventManager::oc4j-128.115.222.7-23943-default" daemon [_thread_blocked, id=17756]
    0x08137000 JavaThread "Thread-102039" [_thread_blocked, id=17754]
    0xb1101400 JavaThread "ActiveMQ Session Task" daemon [_thread_blocked, id=17740]
    0x082d7400 JavaThread "MetricCollector:METRICCOLL50:5" daemon [_thread_blocked, id=17725]
    0x081c8800 JavaThread "RMICallHandler-12" [_thread_blocked, id=17716]
    0x081c8400 JavaThread "RMICallHandler-11" [_thread_blocked, id=17715]
    0x08191400 JavaThread "RMICallHandler-10" [_thread_blocked, id=17701]
    0xb359a800 JavaThread "RMIConnectionThread" [_thread_in_native, id=10419]
    0x080dd800 JavaThread "TimerThread300000" daemon [_thread_blocked, id=10399]
    0x08288400 JavaThread "CacheManager" daemon [_thread_blocked, id=10398]
    0x08268000 JavaThread "RMIConnectionThread" [_thread_in_native, id=10387]
    0xb355e000 JavaThread "EmChartCacheWorker" daemon [_thread_blocked, id=10386]
    0x0811c800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10328]
    0x0811b800 JavaThread "Thread-93" daemon [_thread_in_native, id=10327]
    0x0810f400 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10326]
    0x08100c00 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10324]
    0xb50bc000 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10322]
    0xb5267400 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10320]
    0x081b6800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10318]
    0xb5224800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10314]
    0x081a7c00 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10313]
    0xb35fec00 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10310]
    0x08198c00 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10308]
    0xb4cec800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10306]
    0xb522e400 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10304]
    0x08188800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10302]
    0xb4d2e800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10301]
    0x0816e000 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10298]
    0xb4b4e400 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10297]
    0xb52f8c00 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10294]
    0xb50aa000 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10292]
    0xb4b46800 JavaThread "DestroyJavaVM" [_thread_blocked, id=10153]
    0xb35ffc00 JavaThread "TaskManager" [_thread_blocked, id=10291]
    0x081ce400 JavaThread "Timer-18" [_thread_blocked, id=10288]
    0xb35fd000 JavaThread "Timer-17" [_thread_blocked, id=10287]
    0xb35f1800 JavaThread "Timer-16" [_thread_blocked, id=10286]
    0xb3539400 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10285]
    0xb35acc00 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10282]
    0xb35ba400 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10280]
    0xb3cb7c00 JavaThread "Timer-15" [_thread_blocked, id=10278]
    0xb35cac00 JavaThread "Timer-14" [_thread_blocked, id=10275]
    0xb35ce000 JavaThread "Timer-13" [_thread_blocked, id=10274]
    0xb35b5c00 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10273]
    0xb35bc400 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10271]
    0xb35be800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10269]
    0xb3997800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10266]
    0xb359bc00 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10264]
    0xb353d800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10262]
    0xb39a1400 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10260]
    0xb3996c00 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10258]
    0xb359d400 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10256]
    0xb358c000 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10254]
    0xb3542800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10252]
    0xb355ec00 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10250]
    0xb359e000 JavaThread "Timer-12" [_thread_blocked, id=10247]
    0xb35a5000 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10246]
    0xb35a0800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10244]
    0xb35a2000 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10242]
    0xb3596c00 JavaThread "Timer-11" [_thread_blocked, id=10239]
    0xb3596000 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10238]
    0xb359c400 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10236]
    0xb3595800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10234]
    0xb357fc00 JavaThread "Timer-10" [_thread_blocked, id=10231]
    0xb357f800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10230]
    0xb357d400 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10228]
    0xb3579000 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10226]
    0xb353f800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10223]
    0xb3543400 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10221]
    0xb353ec00 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10219]
    0xb3552400 JavaThread "Timer-9" [_thread_blocked, id=10217]
    0xb3550800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10215]
    0xb355c800 JavaThread "Thread-30" daemon [_thread_in_native, id=10214]
    0xb3544800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10212]
    0xb3548400 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10209]
    0xb3547800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10207]
    0xb354f800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10205]
    0xb354e800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10203]
    0xb399fc00 JavaThread "Thread-23" daemon [_thread_in_native, id=10200]
    0xb3920000 JavaThread "Timer-8" [_thread_blocked, id=10197]
    0xb391e400 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10196]
    0xb3916000 JavaThread "Thread-19" daemon [_thread_in_native, id=10195]
    0xb3915400 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10194]
    0xb49f1800 JavaThread "ActiveMQ Transport: tcp://dai3/128.115.222.163:61616" [_thread_in_native, id=10192]
    0xb4036800 JavaThread "Timer-7" [_thread_blocked, id=10189]
    0xb5225800 JavaThread "Timer-6" [_thread_blocked, id=10188]
    0xb4d23800 JavaThread "SystemThreadGroup-6" [_thread_in_native, id=10187]
    0xb4014800 JavaThread "SystemThreadGroup-5" [_thread_in_native, id=10186]
    0xb49f8400 JavaThread "SystemThreadGroup-4" [_thread_blocked, id=10185]
    0xb4d27c00 JavaThread "Timer-5" [_thread_blocked, id=10184]
    0xb49ff400 JavaThread "Timer-4" [_thread_blocked, id=10183]
    0xb50e2800 JavaThread "Timer-3" [_thread_blocked, id=10182]
    0xb49ea000 JavaThread "Timer-1" daemon [_thread_blocked, id=10180]
    0xb49a4c00 JavaThread "WorkExecutorWorkerThread-1" daemon [_thread_blocked, id=10179]
    0xb499ec00 JavaThread "Thread-8" daemon [_thread_blocked, id=10178]
    0xb496a400 JavaThread "Timer-0" [_thread_blocked, id=10176]
    0xb4d32c00 JavaThread "AWT-XAWT" daemon [_thread_in_native, id=10175]
    0xb501cc00 JavaThread "Java2D Disposer" daemon [_thread_blocked, id=10174]
    0xb4941c00 JavaThread "RMIServer [0.0.0.0:23943] count:1" [_thread_in_native, id=10173]
    0xb4b4d800 JavaThread "RMIServer [0.0.0.0:23791] count:1" [_thread_in_native, id=10172]
    0xb501ac00 JavaThread "JMSServer[salsa:9127]" [_thread_in_native, id=10171]
    0x0837d800 JavaThread "WsMgmtWorkScheduler" daemon [_thread_blocked, id=10170]
    0x08360400 JavaThread "WsMgmtWorkScheduler" daemon [_thread_blocked, id=10169]
    0x08324400 JavaThread "Timer ServiceThread" [_thread_blocked, id=10168]
    0x08368c00 JavaThread "Scheduler ServiceThread" [_thread_blocked, id=10167]
    0x0835b000 JavaThread "Event ServiceThread" [_thread_blocked, id=10166]
    0x0830a800 JavaThread "LogFlusher" daemon [_thread_blocked, id=10164]
    0x0830dc00 JavaThread "LogFlusher" daemon [_thread_blocked, id=10163]
    0x0830f400 JavaThread "LogFlusher" daemon [_thread_blocked, id=10162]
    0x0808c800 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=10159]
    0x0808b000 JavaThread "CompilerThread0" daemon [_thread_blocked, id=10158]
    0x08089c00 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=10157]
    0x08081800 JavaThread "Finalizer" daemon [_thread_blocked, id=10156]
    0x08080400 JavaThread "Reference Handler" daemon [_thread_blocked, id=10155]
    Other Threads:
    0x0807f000 VMThread [id=10154]
    0x0808e400 WatcherThread [id=10160]
    VM state:not at safepoint (normal execution)
    VM Mutex/Monitor currently owned by a thread: None
    Heap
    def new generation total 3648K, used 1498K [0x442a0000, 0x44690000, 0x49160000)
    eden space 3264K, 34% used [0x442a0000, 0x443b6b80, 0x445d0000)
    from space 384K, 100% used [0x445d0000, 0x44630000, 0x44630000)
    to space 384K, 0% used [0x44630000, 0x44630000, 0x44690000)
    tenured generation total 43488K, used 19246K [0x49160000, 0x4bbd8000, 0x842a0000)
    the space 43488K, 44% used [0x49160000, 0x4a42b9d8, 0x4a42ba00, 0x4bbd8000)
    compacting perm gen total 48640K, used 48465K [0x842a0000, 0x87220000, 0x942a0000)
    the space 48640K, 99% used [0x842a0000, 0x871f4458, 0x871f4600, 0x87220000)
    ro space 8192K, 73% used [0x942a0000, 0x94882560, 0x94882600, 0x94aa0000)
    rw space 12288K, 58% used [0x94aa0000, 0x95197448, 0x95197600, 0x956a0000)
    Dynamic libraries:
    0014e000-00156000 r-xp 00000000 08:01 91357260 /lib/tls/librt-2.3.4.so
    00156000-00157000 r-xp 00007000 08:01 91357260 /lib/tls/librt-2.3.4.so
    00157000-00158000 rwxp 00008000 08:01 91357260 /lib/tls/librt-2.3.4.so
    00158000-00162000 rwxp 00158000 00:00 0
    0028b000-002a1000 r-xp 00000000 08:01 91357186 /lib/ld-2.3.4.so
    002a1000-002a2000 r-xp 00015000 08:01 91357186 /lib/ld-2.3.4.so
    002a2000-002a3000 rwxp 00016000 08:01 91357186 /lib/ld-2.3.4.so
    002a5000-003cb000 r-xp 00000000 08:01 91357199 /lib/tls/libc-2.3.4.so
    003cb000-003cd000 r-xp 00125000 08:01 91357199 /lib/tls/libc-2.3.4.so
    003cd000-003cf000 rwxp 00127000 08:01 91357199 /lib/tls/libc-2.3.4.so
    003cf000-003d1000 rwxp 003cf000 00:00 0
    003d3000-003f4000 r-xp 00000000 08:01 91357212 /lib/tls/libm-2.3.4.so
    003f4000-003f5000 r-xp 00020000 08:01 91357212 /lib/tls/libm-2.3.4.so
    003f5000-003f6000 rwxp 00021000 08:01 91357212 /lib/tls/libm-2.3.4.so
    003f8000-003fa000 r-xp 00000000 08:01 91357214 /lib/libdl-2.3.4.so
    003fa000-003fb000 r-xp 00001000 08:01 91357214 /lib/libdl-2.3.4.so
    003fb000-003fc000 rwxp 00002000 08:01 91357214 /lib/libdl-2.3.4.so
    00501000-0050f000 r-xp 00000000 08:01 91357218 /lib/tls/libpthread-2.3.4.so
    0050f000-00510000 r-xp 0000d000 08:01 91357218 /lib/tls/libpthread-2.3.4.so
    00510000-00511000 rwxp 0000e000 08:01 91357218 /lib/tls/libpthread-2.3.4.so
    00511000-00513000 rwxp 00511000 00:00 0
    00623000-00632000 r-xp 00000000 08:01 91357234 /lib/libresolv-2.3.4.so
    00632000-00633000 r-xp 0000f000 08:01 91357234 /lib/libresolv-2.3.4.so
    00633000-00634000 rwxp 00010000 08:01 91357234 /lib/libresolv-2.3.4.so
    00634000-00636000 rwxp 00634000 00:00 0
    00820000-00827000 r-xp 00000000 08:01 68757852 /usr/X11R6/lib/libXi.so.6.0
    00827000-00828000 rwxp 00006000 08:01 68757852 /usr/X11R6/lib/libXi.so.6.0
    0083b000-00848000 r-xp 00000000 08:01 68759646 /usr/X11R6/lib/libXext.so.6.4
    00848000-00849000 rwxp 0000c000 08:01 68759646 /usr/X11R6/lib/libXext.so.6.4
    00870000-00877000 r-xp 00000000 08:01 68763552 /usr/X11R6/lib/libXrender.so.1.2.2
    00877000-00878000 rwxp 00006000 08:01 68763552 /usr/X11R6/lib/libXrender.so.1.2.2
    008b6000-008be000 r-xp 00000000 08:01 68763554 /usr/X11R6/lib/libXcursor.so.1.0.2
    008be000-008bf000 rwxp 00007000 08:01 68763554 /usr/X11R6/lib/libXcursor.so.1.0.2
    008e3000-009be000 r-xp 00000000 08:01 68758178 /usr/X11R6/lib/libX11.so.6.2
    009be000-009c2000 rwxp 000db000 08:01 68758178 /usr/X11R6/lib/libX11.so.6.2
    00b0a000-00b0e000 r-xp 00000000 08:01 68756642 /usr/X11R6/lib/libXtst.so.6.1
    00b0e000-00b0f000 rwxp 00003000 08:01 68756642 /usr/X11R6/lib/libXtst.so.6.1
    00c3e000-00c50000 r-xp 00000000 08:01 91357258 /lib/libnsl-2.3.4.so
    00c50000-00c51000 r-xp 00011000 08:01 91357258 /lib/libnsl-2.3.4.so
    00c51000-00c52000 rwxp 00012000 08:01 91357258 /lib/libnsl-2.3.4.so
    00c52000-00c54000 rwxp 00c52000 00:00 0
    06000000-06417000 r-xp 00000000 08:01 98304002 /u01/app/java/jdk1.6.0_03/jre/lib/i386/client/libjvm.so
    06417000-06430000 rwxp 00417000 08:01 98304002 /u01/app/java/jdk1.6.0_03/jre/lib/i386/client/libjvm.so
    06430000-0684f000 rwxp 06430000 00:00 0
    08048000-08052000 r-xp 00000000 08:01 98320386 /u01/app/java/jdk1.6.0_03/bin/java
    08052000-08053000 rwxp 00009000 08:01 98320386 /u01/app/java/jdk1.6.0_03/bin/java
    08053000-0877f000 rwxp 08053000 00:00 0
    442a0000-44690000 rwxp 442a0000 00:00 0
    44690000-49160000 rwxp 44690000 00:00 0
    49160000-4bbd8000 rwxp 49160000 00:00 0
    4bbd8000-842a0000 rwxp 4bbd8000 00:00 0
    842a0000-87220000 rwxp 842a0000 00:00 0
    87220000-942a0000 rwxp 87220000 00:00 0
    942a0000-94883000 r-xs 00001000 08:01 98304677 /u01/app/java/jdk1.6.0_03/jre/lib/i386/client/classes.jsa
    94883000-94aa0000 rwxp 94883000 00:00 0
    94aa0000-95198000 rwxp 005e4000 08:01 98304677 /u01/app/java/jdk1.6.0_03/jre/lib/i386/client/classes.jsa
    95198000-956a0000 rwxp 95198000 00:00 0
    956a0000-95779000 rwxp 00cdc000 08:01 98304677 /u01/app/java/jdk1.6.0_03/jre/lib/i386/client/classes.jsa
    95779000-95aa0000 rwxp 95779000 00:00 0
    95aa0000-95aa4000 r-xs 00db5000 08:01 98304677 /u01/app/java/jdk1.6.0_03/jre/lib/i386/client/classes.jsa
    95aa4000-95ea0000 rwxp 95aa4000 00:00 0
    b0b49000-b0b5e000 r-xp 00000000 08:01 98287757 /u01/app/java/jdk1.6.0_03/jre/lib/i386/libdcpr.so
    b0b5e000-b0b71000 rwxp 00014000 08:01 98287757 /u01/app/java/jdk1.6.0_03/jre/lib/i386/libdcpr.so
    b0f00000-b0f50000 rwxp b0f00000 00:00 0
    b0f50000-b1000000 ---p b0f50000 00:00 0
    b1100000-b11fd000 rwxp b1100000 00:00 0
    b11fd000-b1200000 ---p b11fd000 00:00 0
    b1226000-b122b000 r-xs 0002f000 08:01 98533404 /u01/app/oc4j/oc4j-10.1.3.3.0/j2ee/home/applications/dai-core/dai-core-pre1.1/WEB-INF/lib/dai-core-pre1.1.jar
    b122b000-b122d000 r-xs 0001a000 08:01 98533399 /u01/app/oc4j/oc4j-10.1.3.3.0/j2ee/home/applications/dai-core/dai-core-pre1.1/WEB-INF/lib/commons-modeler-2.0.1.jar
    b122d000-b122f000 r-xs 0000a000 08:01 98533396 /u01/app/oc4j/oc4j-10.1.3.3.0/j2ee/home/applications/dai-core/dai-core-pre1.1/WEB-INF/lib/commons-codec-1.3.jar
    b122f000-b1233000 r-xs 00031000 08:01 98533394 /u01/app/oc4j/oc4j-10.1.3.3.0/j2ee/home/applications/dai-core/dai-core-pre1.1/WEB-INF/lib/ciacCommmon-1.1.jar
    b1233000-b1234000 r-xs 00000000 08:01 98533393 /u01/app/oc4j/oc4j-10.1.3.3.0/j2ee/home/applications/dai-core/dai-core-pre1.1/WEB-INF/lib/ciac-bloomdex.jar
    b1234000-b1236000 r-xs 00001000 08:01 98533414 /u01/app/oc4j/oc4j-10.1.3.3.0/j2ee/home/applications/dai-core/dai-core-pre1.1/WEB-INF/lib/slf4j-api-1.1.0.jar
    b1236000-b1241000 r-xs 00073000 08:01 98533409 /u01/app/oc4j/oc4j-10.1.3.3.0/j2ee/home/applications/dai-core/dai-core-pre1.1/WEB-INF/lib/jsp-api-2.1.jar
    b1241000-b1242000 r-xs 00001000 08:01 98533415 /u01/app/oc4j/oc4j-10.1.3.3.0/j2ee/home/applications/dai-core/dai-core-pre1.1/WEB-INF/lib/slf4j-log4j12-1.1.0.jar
    b1242000-b1249000 r-xs 00053000 08:01 98533410 /u01/app/oc4j/oc4j-10.1.3.3.0/j2ee/home/applications/dai-core/dai-core-pre1.1/WEB-INF/lib/log4j-1.2.14.jar
    b1249000-b124e000 r-xs 00040000 08:01 98533397 /u01/app/oc4j/oc4j-10.1.3.3.0/j2ee/home/applications/dai-core/dai-core-pre1.1/WEB-INF/lib/commons-httpclient-3.0.1.jar
    b124e000-b1265000 r-xs 00112000 08:01 98533418 /u01/app/oc4j/oc4j-10.1.3.3.0/j2ee/home/applications/dai-core/dai-core-pre1.1/WEB-INF/lib/xercesImpl-2.8.1.jar
    b1265000-b1268000 rwxp b1265000 00:00 0
    b1268000-b12b6000 rwxp b1268000 00:00 0
    b12b6000-b12b9000 rwxp b12b6000 00:00 0
    b12b9000-b1307000 rwxp b12b9000 00:00 0
    b1307000-b130a000 ---p b1307000 00:00 0
    b130a000-b1358000 rwxp b130a000 00:00 0
    b1358000-b135b000 rwxp b1358000 00:00 0
    b135b000-b13a9000 rwxp b135b000 00:00 0
    b13a9000-b13ac000 rwxp b13a9000 00:00 0
    b13ac000-b13fa000 rwxp b13ac000 00:00 0
    b13fa000-b13fd000 rwxp b13fa000 00:00 0
    b13fd000-b144b000 rwxp b13fd000 00:00 0
    b144b000-b144e000 rwxp b144b000 00:00 0
    b144e000-b149c000 rwxp b144e000 00:00 0
    b149c000-b149f000 rwxp b149c000 00:00 0
    b149f000-b14ed000 rwxp b149f000 00:00 0
    b14ed000-b14f0000 ---p b14ed000 00:00 0
    b14f0000-b153e000 rwxp b14f0000 00:00 0
    b153e000-b1541000 ---p b153e000 00:00 0
    b1541000-b158f000 rwxp b1541000 00:00 0
    b158f000-b1592000 ---p b158f000 00:00 0
    b1592000-b15e0000 rwxp b1592000 00:00 0
    b15e0000-b15e3000 rwxp b15e0000 00:00 0
    b15e3000-b1631000 rwxp b15e3000 00:00 0
    b1631000-b1634000 ---p b1631000 00:00 0
    b1634000-b1682000 rwxp b1634000 00:00 0
    b1682000-b1685000 rwxp b1682000 00:00 0
    b1685000-b16d3000 rwxp b1685000 00:00 0
    b16d3000-b16d6000 ---p b16d3000 00:00 0
    b16d6000-b1724000 rwxp b16d6000 00:00 0
    b1724000-b1727000 rwxp b1724000 00:00 0
    b1727000-b1775000 rwxp b1727000 00:00 0
    b1775000-b1778000 ---p b1775000 00:00 0
    b1778000-b17c6000 rwxp b1778000 00:00 0
    b17c6000-b17c9000 ---p b17c6000 00:00 0
    b17c9000-b1817000 rwxp b17c9000 00:00 0
    b1817000-b181a000 rwxp b1817000 00:00 0
    b181a000-b1868000 rwxp b181a000 00:00 0
    b1868000-b186b000 rwxp b1868000 00:00 0
    b186b000-b18b9000 rwxp b186b000 00:00 0
    b18b9000-b18bc000 ---p b18b9000 00:00 0
    b18bc000-b190a000 rwxp b18bc000 00:00 0
    b190a000-b190d000 ---p b190a000 00:00 0
    b190d000-b195b000 rwxp b190d000 00:00 0
    b195b000-b195e000 rwxp b195b000 00:00 0
    b195e000-b19ac000 rwxp b195e000 00:00 0
    b19ac000-b19af000 rwxp b19ac000 00:00 0
    b19af000-b19fd000 rwxp b19af000 00:00 0
    b19fd000-b1a00000 ---p b19fd000 00:00 0
    b1a00000-b1a4e000 rwxp b1a00000 00:00 0
    b1a4e000-b1a51000 rwxp b1a4e000 00:00 0
    b1a51000-b1a9f000 rwxp b1a51000 00:00 0
    b1a9f000-b1aa2000 ---p b1a9f000 00:00 0
    b1aa2000-b1af0000 rwxp b1aa2000 00:00 0
    b1af0000-b1af3000 rwxp b1af0000 00:00 0
    b1af3000-b1b41000 rwxp b1af3000 00:00 0
    b1b41000-b1b44000 ---p b1b41000 00:00 0
    b1b44000-b1b92000 rwxp b1b44000 00:00 0
    b1b92000-b1b95000 rwxp b1b92000 00:00 0
    b1b95000-b1be3000 rwxp b1b95000 00:00 0
    b1be3000-b1be6000 ---p b1be3000 00:00 0
    b1be6000-b1c34000 rwxp b1be6000 00:00 0
    b1c34000-b1c37000 rwxp b1c34000 00:00 0
    b1c37000-b1c85000 rwxp b1c37000 00:00 0
    b1c85000-b1c88000 ---p b1c85000 00:00 0
    b1c88000-b1cd6000 rwxp b1c88000 00:00 0
    b1cd6000-b1cd9000 ---p b1cd6000 00:00 0
    b1cd9000-b1d27000 rwxp b1cd9000 00:00 0
    b1d27000-b1d2a000 rwxp b1d27000 00:00 0
    b1d2a000-b1d78000 rwxp b1d2a000 00:00 0
    b1d78000-b1d7b000 rwxp b1d78000 00:00 0
    b1d7b000-b1dc9000 rwxp b1d7b000 00:00 0
    b1dc9000-b1dcc000 ---p b1dc9000 00:00 0
    b1dcc000-b1e1a000 rwxp b1dcc000 00:00 0
    b1e1a000-b1e1d000 ---p b1e1a000 00:00 0
    b1e1d000-b1e6b000 rwxp b1e1d000 00:00 0
    b1e6b000-b1e6e000 rwxp b1e6b000 00:00 0
    b1e6e000-b1ebc000 rwxp b1e6e000 00:00 0
    b1ebc000-b1ebf000 ---p b1ebc000 00:00 0
    b1ebf000-b1f0d000 rwxp b1ebf000 00:00 0
    b1f0d000-b1f10000 rwxp b1f0d000 00:00 0
    b1f10000-b1f5e000 rwxp b1f10000 00:00 0
    b1f5e000-b1f61000 rwxp b1f5e000 00:00 0
    b1f61000-b1faf000 rwxp b1f61000 00:00 0
    b1faf000-b1fb2000 ---p b1faf000 00:00 0
    b1fb2000-b2022000 rwxp b1fb2000 00:00 0
    b2022000-b2100000 ---p b2022000 00:00 0
    b2111000-b2114000 ---p b2111000 00:00 0
    b2114000-b2162000 rwxp b2114000 00:00 0
    b2162000-b2165000 ---p b2162000 00:00 0
    b2165000-b21b3000 rwxp b2165000 00:00 0
    b21b3000-b21b6000 ---p b21b3000 00:00 0
    b21b6000-b2204000 rwxp b21b6000 00:00 0
    b2204000-b2207000 rwxp b2204000 00:00 0
    b2207000-b2255000 rwxp b2207000 00:00 0
    b2255000-b2258000 ---p b2255000 00:00 0
    b2258000-b22a6000 rwxp b2258000 00:00 0
    b22a6000-b22a9000 rwxp b22a6000 00:00 0
    b22a9000-b22f7000 rwxp b22a9000 00:00 0
    b22f7000-b22fa000 ---p b22f7000 00:00 0
    b22fa000-b2348000 rwxp b22fa000 00:00 0
    b2348000-b234b000 ---p b2348000 00:00 0
    b234b000-b2399000 rwxp b234b000 00:00 0
    b2399000-b239c000 ---p b2399000 00:00 0
    b239c000-b23ea000 rwxp b239c000 00:00 0
    b23ea000-b23ed000 rwxp b23ea000 00:00 0
    b23ed000-b243b000 rwxp b23ed000 00:00 0
    b243b000-b243e000 ---p b243b000 00:00 0
    b243e000-b248c000 rwxp b243e000 00:00 0
    b248c000-b248f000 ---p b248c000 00:00 0
    b248f000-b24dd000 rwxp b248f000 00:00 0
    b24dd000-b24e0000 ---p b24dd000 00:00 0
    b24e0000-b252e000 rwxp b24e0000 00:00 0
    b252e000-b2531000 ---p b252e000 00:00 0
    b2531000-b257f000 rwxp b2531000 00:00 0
    b257f000-b2582000 ---p b257f000 00:00 0
    b2582000-b25d0000 rwxp b2582000 00:00 0
    b25d0000-b25d3000 ---p b25d0000 00:00 0
    b25d3000-b2621000 rwxp b25d3000 00:00 0
    b2621000-b2624000 ---p b2621000 00:00 0
    b2624000-b2672000 rwxp b2624000 00:00 0
    b2672000-b2675000 ---p b2672000 00:00 0
    b2675000-b26c3000 rwxp b2675000 00:00 0
    b26c3000-b26c6000 rwxp b26c3000 00:00 0
    b26c6000-b2714000 rwxp b26c6000 00:00 0
    b2714000-b2717000 ---p b2714000 00:00 0
    b2717000-b2765000 rwxp b2717000 00:00 0
    b2765000-b2768000 ---p b2765000 00:00 0
    b2768000-b27b6000 rwxp b2768000 00:00 0
    b27b6000-b27b9000 ---p b27b6000 00:00 0
    b27b9000-b2807000 rwxp b27b9000 00:00 0
    b2807000-b280a000 ---p b2807000 00:00 0
    b280a000-b2858000 rwxp b280a000 00:00 0
    b2858000-b285b000 ---p b2858000 00:00 0
    b285b000-b28a9000 rwxp b285b000 00:00 0
    b28a9000-b28ac000 ---p b28a9000 00:00 0
    b28ac000-b28fa000 rwxp b28ac000 00:00 0
    b28fa000-b28fd000 ---p b28fa000 00:00 0
    b28fd000-b294b000 rwxp b28fd000 00:00 0
    b294b000-b294e000 ---p b294b000 00:00 0
    b294e000-b299c000 rwxp b294e000 00:00 0
    b299c000-b299f000 ---p b299c000 00:00 0
    b299f000-b29ed000 r

    I found ConcurrentReaderHashMap in one of the jar files included with oc4j, j2ee/home/lib/concurrent.jar. So, it looks like it comes from one of the jars for Oracle's oc4j implementation. This is an error that occurs intermittently when stopping oc4j or when reinstalling an application. So, it looks like it is an error that I should report to Oracle. Correct? Or is there something in my code that is likely causing this error? I am running this under the 1.6.0_03 JVM. Is there an incompatibility in the oswego package with 1.6?

  • CONCURRENT SET

    Hello,
    Is there any concurrent implementation of HashSet?
    CopyOnWriteArraySet is not useful for me (I'll have a lot of threads reading and writing on this set)
    And ConcurrentSkipListSet keeps the order of the elements, and for me the order is not important (as a normal set).
    And I wouldn't want to use a Collections.synchronizedSet(...), because of too much locking.
    Any alternative?
    Thanks.

    Hello,
    Yes, I've made test cases not with Set but with ConcurrentHashMap and Hashtable/Collections.synchronizedMap(). With hundreds of threads getting/putting in these collections (as my app does), the behaivour of ConcurrentHashMap is much better than the other solutions.
    That's why I thought that with Collections.synchronizedSet against any concurrent implementation of Set the conclusion would be the same.
    But as Caffeine says, I can try with ConcurrentHashMap asking for the key and ignoring the value.
    Thanks.

  • Java.util.concurrent.ConcurrentHashMap

    All,
    I prefer to use the java.util.ConcurrentHashMap over a Hashtable but there are some points regarding this structure that are not very clear to me.
    From java.util.concurrent: Class ConcurrentHashMap:
    "A hash table supporting full concurrency of retrievals and adjustable expected concurrency for updates. This class obeys the same functional specification as Hashtable, and includes versions of methods corresponding to each method of Hashtable.
    *+However, even though all operations are thread-safe, retrieval operations do not entail locking, and there is not any support for locking the entire table in a way that prevents all access. This class is fully interoperable with Hashtable in programs that rely on its thread safety but not on its synchronization details. Iterators are designed to be used by only one thread at a time."+ *
    Also from: Java API: Package java.util.concurrent, we read:
    "The "Concurrent" prefix used with some classes in this package is a shorthand indicating several differences from similar "synchronized" classes. For example java.util.Hashtable and Collections.synchronizedMap(new HashMap()) are synchronized. But ConcurrentHashMap is "concurrent". A concurrent collection is thread-safe, but not governed by a single exclusion lock. In the particular case of ConcurrentHashMap, it safely permits any number of concurrent reads as well as a tunable number of concurrent writes. "Synchronized" classes can be useful when you need to prevent all access to a collection via a single lock, at the expense of poorer scalability. In other cases in which multiple threads are expected to access a common collection, "concurrent" versions are normally preferable. And unsynchronized collections are preferable when either collections are unshared, or are accessible only when holding other locks."
    Based on above, is this correct of I say:
    When using a structure like Hashtable, all the methods or operations are synchronized,
    meaning if one thread is accessing the Hashtable (by get(), put(),... or other methods on this structure), it owns the lock and all other threads will lock out until the thread that owns the lock releases the lock; which means only one thread can access the hash table at a time; which can cause performance issues.
    We need to use a synchronized block or method only of two threads modify a "shared resource", if they do not modify a shared resource, we do not need to use the synchronization.
    On the other hand, the methods of ConcurrentHashMap are not synchronized; so multiple threads can access the ConcurrentHashMap at the same time. But isn't the ConcurrentHashMap itself the "shared resource" that threads are accessing? Should we use it only if the threads are reading from map and not writing to it? And then if threads also write to the structure, then it looks like its better to not to use the ConcurrentHashMap, rather use the regular HashMap with the synchronized wrapper?
    Any help is greatly appreciated.

    We need to use a synchronized block or method only of two threads modify a "shared resource", if they do not modify a shared resource, we do not need to use the synchronization. Actually, you need to synchronize access to the shared resource for both readers and writers. If one thread is updating an unsynchronized HashMap, and a concurrent thread tries to read that map, it may be in an inconsistent state. When synchronizing on the map, the reader will be blocked until the writer completes.
    What you don't need to do is prevent multiple readers from accessing the map, if there's no writer. However, a synchronized map or HashTable will single-thread reads as well as writes.
    On the other hand, the methods of ConcurrentHashMap are not synchronized; so multiple threads can access the ConcurrentHashMap at the same time. But isn't the ConcurrentHashMap itself the "shared resource" that threads are accessing? No, it's actually synchronized at a finer level. Without getting into the details of HashMap implementation, an object's hashcode is used to identify a linked list of hashmap entries. The only time that you have a concurrency issue is when a reader and writer are accessing the same list. So the ConcurrentHashMap locks only the list that's being updated, and allows readers (and writers!) to access the other bucket lists. Plus, it allows two readers to proceed concurrently.

  • ConcurrentHashMap scenario

    Hi all,
    Following is my scenario, let me know if ConcurrentHashMap is the soln.
    I have a cache (map) with one process say P1 (having n number of threads) does inserting into map and another process say P2 (with m number of threads) does updation of the values (that were inserted).
    Threads of P1 insert unique key / value pairs, so i thought, to do insertion faster concurrent hashmap will be better choice (with concurrency level = number of threads of P1).
    The issue is, threads of P2 get the value from the map and update the value. If, for a given key the insertion by a P1 thread and get() by P2 thread happens simultaneously, P2 thread may get the value as null....if hashtable is used, I will not get this situation as get and put are synchronized...but I will not get the performance benefit of Conccurent hashmap (during insertion)..
    This will be a large scale application with up to two million inserts tobe taken care by P1 threads(in total) and same number of updates by P2 threads.
    Please let me know your comments on this...

    harry123 wrote:
    There is no guarantee but we expect most of the times this will be the case, for other cases when the P2 gets a value first (and the corresponding insert by P1 has not been done).....
    P2 will put the value in a different cache, and its P1's responsibility to check the other cache and merge it the main cache.
    Well this solution can be applied to the issue I presented but in that we are increasing the chances of P2 not finding the value when it needs to be updated...thereby increasing number of values that go into second cache..there by putting more work on P1This is what I thought: you don't have a guarantee in either case (hashmap or concurrenthashmap). Since you're not providing a happens-before guarantee with HashMap, I don't see it as a big deal that you're not getting such a guarantee from ConcurrentHashMap either. If it is important, you need to provide that guarantee somehow, or structure your code to deal with a lack thereof.
    I'm not clear on what your end goal is; if you could elaborate, then maybe someone could provide suggestions.

  • ConcurrentHashMap()

    Hey, I had a Hashtable and I've tried to replace it with a ConcurrentHashMap but I keep getting a cannot be resolved or isn't a type error - anyone know how comes? I'm importing java.util.*; and downloaded java 1.5 ages ago.
    Thanks!
    jess

    Hey, I had a Hashtable and I've tried to replace it
    with a ConcurrentHashMap but I keep getting a cannot
    be resolved or isn't a type error - Right, because if you look at the inheritance hierarchy for ConcurrentHashMap you won't see Hashtable.
    ConcurrentHashMap extends AbstractMap extends Object. So if your variable's compile time type is a java.util.Map you can swap a Hashtable with a ConcurrentHashMap, because both classes implement that interface.
    Map map = new ConcurrentHashMap();
    // Map map = new Hashtable();It's a great argument in favor of always using the interfaces as your variable's compile time types, because that makes it possible to switch implementations as needed without affecting clients. Using concrete types locks you in.
    %

  • How can i get the all values from the Property file to Hashtable?

    how can i get the all values from the Property file to Hashtable?
    ok,consider my property file name is pro.PROPERTIES
    and it contain
    8326=sun developer
    4306=sun java developer
    3943=java developer
    how can i get the all keys & values from the pro.PROPERTIES to hashtable
    plz help guys..............

    The Properties class is already a subclass of Hashtable. So if you have a Properties object, you already have a Hashtable. So all you need to do is the first part of that:Properties props = new Properties();
    InputStream is = new FileInputStream("tivoli.properties");
    props.load(is);

  • Unable to reference items in a hashtable

    HI,
    I'm having a bad PowerShell day today!
    My sample script to read in a text file and put the data into a hash table works just fine:
    $InputFile=Get-Content C:\Out\ktf06011.REQ
    $CurrentUserHashTable = @{}
    ForEach ($Line in $InputFile)
    $Data=$Line.Split("=")
    $Label=$Data[0].Trim()
    $Label=$Label.Insert(($Label.Length),"`"")
    $Label=$Label.Insert(0,"`"")
    $Value=$Data[1].Trim()
    $Value=$Value.Insert(($Value.Length),"`"")
    $Value=$Value.Insert(0,"`"")
    $CurrentUserHashTable.Add($Label,$Value)
    $CurrentUserHashTable 
    However, when I use this within a script that uses a file system watcher event to discover the presence of the text file, I cannot get anything from the hash table. I can see my variables being created, ready to pass on to the .add statement. I have found
    a workaround for now - not using a hash table - but would love to know why I see this behaviour and suggestions for getting at the data.
    Here is the code that I'm having trouble with.
    $folder = 'c:\In'
    $OutFolder = 'c:\Out'
    $filter = '*.*'
    $CurrentUserHashTable = $NULL
    $FileSystemWatcher = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
    Register-ObjectEvent $FileSystemWatcher Created -SourceIdentifier FileCreated -Action {
    $name = $Event.SourceEventArgs.Name
    $InputFile=Get-Content $folder\$name
    ForEach ($Line in $InputFile)
    #Write-Host $Line
    $CurrentUserHashTable = @{}
    $Data=$Line.Split("=")
    #Write-Host "Data: " $Data
    $Label=$Data[0].Trim()
    $Label=$Label.Insert(($Label.Length),"`"")
    $Label=$Label.Insert(0,"`"")
    #Write-Host "Label: " $Label
    $Value=$Data[1].Trim()
    $Value=$Value.Insert(($Value.Length),"`"")
    $Value=$Value.Insert(0,"`"")
    #Write-Host "Value: " $Value
    $CurrentUserHashTable.Add($Label,$Value)
    $CurrentUserHashTable
    Move-Item $folder\$name $OutFolder -Force
    #Label: "ID"
    #Value: "abc00001"
    #Label: "PID"
    #Value: "00001"
    #Label: "Title"
    #Value: "Mr"
    #Label: "Initials"
    #Value: "XY"
    #Label: "Forename"
    #Value: "Mickey"
    #Label: "Surname"
    #Value: "Mouse"
    #Label: "Siteabbrev"
    #Value: "UK"
    #Label: "Status"
    #Value: "STAFF"
    #Label: "BUabbrev"
    #Value: "NOBU"
    #Label: "Department"
    #Value: "Finance"
    Note the commented bits at the bottom are the output of
    Write-Host "Value: " $Value
     and
    Write-Host "Label: " $Label
    Also, if the following are placed within the loop, I see all data items being returned, so I know that they are added to the hash table. If they are added outside the loop, I just get the final entry "Department"
    Write-Host "Keys:" $CurrentUserHashTable.Keys
    Write-Host "Values:" $CurrentUserHashTable.Values
    Many thanks,
    Jon

    Rhys,
    Thanks that was so obvious, I couldn't see it!
    I knew the answer would be simple.
    Made the amendment to my script and can now get at the data in the hashtable, via (e.g.)
    $Department=$CurrentUserHashTable.'"Department"'
    Thanks again.
    Jon

  • Difference Between HashMap and HashTable

    Difference Between HashMap and HashTable
    Please explain with an example

    I have a situation in Java Collection and i am not
    able to figure a good solution. I am scared about the
    performance and memory that wil be used
    I have 5 List objects with thousands and thousands of
    records in it. The List is populated by a database
    query using jdbcTemplate which return like 200,000
    records
    Each record is identified by POLICY_ID. They may be
    List with multiple records for a POLICY_ID
    I want to extract each POLICY_ID from all the 5 List
    and make a single List object for each POLICY_ID and
    for each List and pass it to a print job which will
    print the data for a POLICY_ID
    Example
    Let say we have POLICY_ID = 15432
    List1 has one record for 15432
    List2 has one record for 15432
    List3 has one record for 15432
    List4 has three record for 15432
    List5 has three record for 15432
    From the 200,000 records in List1 i want to generate
    a seperate list with 1 record for policy id 15432 and
    let name is Listperpolicy
    after this logic we have
    Listperpolicy1
    Listperpolicy2
    Listperpolicy3
    Listperpolicy4
    Listperpolicy5
    call print job ( Listperpolicy1, Listperpolicy2,
    Listperpolicy3, Listperpolicy4, Listperpolicy5)
    Please let me know
    Thanks a Lotttttttttdon't worry about performance until you've got a working application. second-guessing what the performance bottlenecks will be is futile

  • How can I get the total "values" in a hashtable ?

    i know that i can get the total values in a hashtable by hash.elements() method. It returns an
    enumeration with all the values present in this hashtable. this is fine upto here.
    Now the preoblem is:
    According to what rule this enumeration will be returned. I mean..
    If i added in key A with value a,
    then key B with value b;
    then key C with value c;
    then key D with value d;
    (They all are objects of type String)
    now i call ... hash.elements(); Suppose it returns Enumeration enum;.
    Now in what order they all are present in this hashtable.
    Meaning is that if i move arond this enum in what sequence they all will be returned.
    option A ) In the same order as they were inserted in hashtable.
    option B ) According to LIFO;
    option C) There is no fix rules , simply it return all the elements and u cannot judge that the first element in enum was really the first element inserted in the hashtable and the second element of enum was really the second element inserted in the hashtable.
    What do u think..which option is correct ?
    Ny idea will highly appreciated.
    Thanks in advance.
    Sanjeev Dhiman

    hi, i am again..
    boss ! this is not true..u just change the order and or change the keys and something like ...
    "Sanjeev", "hello"
    "Dhiman", "hi"
    "Technosys" ,"Services"
    u will find that its not LIFO..really i was thinking before coding my project that option A is correct and with knowledge i wrote 3 - 4 classes but when i run the programm its starts throwing errors.
    so, i posted this question. I think "apppu" is right.
    I think , firstly hash is calculated for each value and that value is returned which can be received in a fastest way and hence not necessarily in LIFO and FIFO..
    Thanks to u also as u gave ur precious time for me.
    Once again.
    Thank you very much.
    Sanjeev Dhiman

  • Problem in Jtree while retrieving values from a hashtable

    Hi
    I am trying to show some values in a Jtree.I am receiving the values in a hashtable.The hashtable contains unique key but duplicate values.i want to show that values of that hashtable in a tree(but unique values)and under each value show all the key of it.can you please tell me how to do that.
    thanks

    If i understand right, you want to do something like this:
                   Hashtable values = yourhashtable;        
              DefaultMutableTreeNode root = new DefaultMutableTreeNode("Values");
              HashMap<Object, DefaultMutableTreeNode> nodes = new HashMap<Object, DefaultMutableTreeNode>();
              Iterator ii = values.keySet().iterator();
              while (ii.hasNext()) {
                   Object key = ii.next();
                   Object value = values.get(key);
                   if (nodes.containsKey(value)) {
                        DefaultMutableTreeNode node = nodes.get(value);
                        DefaultMutableTreeNode child = new DefaultMutableTreeNode(key);
                        node.add(child);
                   } else {
                        DefaultMutableTreeNode node = new DefaultMutableTreeNode(value);
                        DefaultMutableTreeNode child = new DefaultMutableTreeNode(key);
                        node.add(child);
                        nodes.put(value, node);
                        root.add(node);
              JTree tree = new JTree(root);Hope this helps,
    Alex.

  • Reading Values from a Hashtable.Please guideu

    Chaps,
    I am in a strange situation
    I am having a hashtable with the flwg values
    Entertainment Games
    Entertainment Video
    PIM Calculator
    Entertainment Jump
    Settings Set
    Entertainment Poker
    Now,I need to search this hashtable for the
    Object 'Entertainment' and whatever is the
    value of this,is put in an Array
    for this I am using:
    String s[];
    Enumeration e;
    for(int i=0; i<ht.size(); i++){
    String s = (String)ht.get("Entertainment");
    // I am stuck after this? Can some one please help?       
             

    Object value = ht.get("Entertainment");
    But if you are doing this (I can't tell if this is what you're doing from your first post, though):
    ht.put("Entertainment", onething);
    ht.put("Entertainment", anotherthing);
    ht.put("Entertainment", athirdthing);
    Then there will only be athirdthing in the table, cuz it'll overwrite the previous values.

  • Need help in using hashtable as a property of a form bean

    Hi,
    Is it possible to use a hashtable as a property of the bean.
    Well this is the problem i have
    I am using a hashtable as property and i want it to store from(/retrive into} form as ints/strings
    I have a
    JSP Page
    SampleAction --Action
    SampleForm --ActionForm
    Sample(bean)
    =============
    JSP Page
    (within the html:form tag)
    <html:text property="sample.number" />
    ====================
    struts-config links to
    SampleAction
    SampleForm
    ==============
    SampleForm
    Sample sample = new Sample();
    reset(){ ...impl...}
    validate(){.... impl.....}
    =================
    Sample.java
    private Hashtable prop = new Hashtable();
    public int getNumber()
       return ((Integer)prop.get("number")).intValue();
    public void setNumber(int number)
       prop.put("number",new Integer(number));
    ====================================
    this setup understandbly gives me a error like this
    no getter method for property sample.number
    PLEASE DO remember that i have a large number of mixed types in my form that needs to be populated into the bean and i detest using that many variables(in the bean)
    I NEED TO A KNOW A SOLN. PLEASE
    Thanx in advance
    cheers
    Ash

    Hi,
    I think the solution for your problem is
    put a form tag in your jsp page.
    name it as your form name defined in the struts-config.xml.
    in your case
    it is 'sample'.
    And make changes in the html:text tag like,
    <html:text name="sample" property="number" />
    Hope it will work.. have fun !!!

  • How to put data into a hashtable from a text file

    I need some help to put the words in a text file to a hashtable.The text file
    consist of words and the following set of punctuation marks {, . ; : } and spaces.
    thanks in advance.

    Navy_Coder wrote:
    6 zebras.But you must marry his eldest daughter as well, for that dowry.

  • Need to run a prog on 1.4 which is running on 1.5. .....using two hashtable

    hello,
    I've developed a program which is prefectly working on java 1.5.0 version.
    but when run on java1.4.0. it gives run time error in this code.
    first i'm getting error in second hashtable. put function where i'm using key as an integer.this is running on 1.5 version but have to change key as string on 1.4. but after that it is still not working properly.
    I want that when i clicked on open then it must show both file
    1. that have hdr extension
    2. that have same name as the corrseponding .hdr file but without extension.
    this program show desired result on 1.5 but on 1.4 it display only .hdr file.
    pls. help me regarding this .
    // class hdr file filter
    import java.io.File;
    import java.util.Hashtable;
    import java.util.Enumeration;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    public class hdrFileFilter extends FileFilter {
    private Hashtable filters = null;
    private Hashtable noextensionfilter = null;
    private String noextensionname=null;
    private String extensionname = null;
    private String description = null;
    private String fullDescription = null;
    private boolean useExtensionsInDescription = true;
    private String fname = null;
    public File noextensionarray[];
    int count=0;
    int counthdr=0;
    int i=0;     
         //all files are accepted.
    public hdrFileFilter()
         this.filters = new Hashtable();
         //Creates a file filter that accepts files with the given extension.
    public hdrFileFilter(String extension)
         this(extension,null);
         //Creates a file filter that accepts the given file type.
    public hdrFileFilter(String extension, String description)
         this();
         if(extension!=null)
         addExtension(extension);
         if(description!=null) setDescription(description);
         //Return true if this file should be shown in the directory pane,false if it shouldn't.
    public boolean accept(File f) {
         if(f != null) {
         if(f.isDirectory()) {
              return true;
         String extension = getExtension(f);
         if(extension != null && filters.get(getExtension(f)) != null)
              fname=f.getName();
              extensionname=fname.substring(0,fname.lastIndexOf('.'));
              counthdr+=1;
              return true;
         if(extension == null)
              noextensionfilter=new Hashtable(20);
              noextensionname=f.getName();          
              noextensionfilter.put(count,noextensionname);
              count=count + 1;
              if(noextensionfilter.get(count) == extensionname)
                   noextensionarray=new File[20];
                   noextensionarray=f
                   System.out.println("file:" +noextensionarray[i]);
                   i++;
                   return true;               
         return false;
         //Return the extension portion of the file's name .
    public String getExtension(File f)
              if(f != null)
                   String filename = f.getName();
                   int i = filename.lastIndexOf('.');
                   if(i>0 && i<filename.length()-1)
                        return filename.substring(i+1).toLowerCase();
              return null;
         //Adds a filetype "dot" extension to filter against.
    public void addExtension(String extension)
         if(filters == null)
         filters = new Hashtable(20);
         filters.put(extension.toLowerCase(), this);
         fullDescription = null;
    public String getDescription()
              if(fullDescription == null)
                   if(description == null || isExtensionListInDescription())
                        fullDescription = description==null ? "(" : description + " (";
                        // build the description from the extension list
                        Enumeration extensions = filters.keys();
                        if(extensions != null)
                             Object nn=extensions.nextElement();
                             fullDescription += "." + nn;     
                             while (extensions.hasMoreElements())
                                  fullDescription += ", ." + nn;
                        fullDescription += ")";
                   else
                        fullDescription = description;
              return fullDescription;
    public void setDescription(String description)
         this.description = description;
         fullDescription = null;
    public void setExtensionListInDescription(boolean b) {
         useExtensionsInDescription = b;
         fullDescription = null;
              public boolean isExtensionListInDescription()
              return useExtensionsInDescription;

    Might be fixable if you do something like
    javac -target 1.4
    Bytecodes are different in 1.5 and thus not backward compatible

Maybe you are looking for