[jira] [Commented] (JXPATH-152) Concurrent access on hashmap of JXPathIntrospector
[ https://issues.apache.org/jira/browse/JXPATH-152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14613991#comment-14613991 ] Michele Vivoda commented on JXPATH-152: --- 1.4 snapshot is here https://github.com/apache/commons-jxpath > Concurrent access on hashmap of JXPathIntrospector > -- > > Key: JXPATH-152 > URL: https://issues.apache.org/jira/browse/JXPATH-152 > Project: Commons JXPath > Issue Type: Bug >Affects Versions: 1.3 > Environment: Java5, Windows/AIX >Reporter: pleutre >Assignee: Matt Benson >Priority: Minor > Fix For: 1.4 > > Original Estimate: 24h > Remaining Estimate: 24h > > JXPathIntrospector.registerDynamicClass method can be called in static part > of classes. > If two classes A & B try to registerDynamicClass in the same time a > concurrent access exception can append on hashmap of JXPathIntrospector. > Replace hashmap by concurrent hashmap or synchronized access to these > hashmaps. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (JXPATH-152) Concurrent access on hashmap of JXPathIntrospector
[ https://issues.apache.org/jira/browse/JXPATH-152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14607553#comment-14607553 ] Nicholas DiPiazza commented on JXPATH-152: -- Does this issue affect 1.2 release of commons-jxpath library as well? I am calling org.apache.commons.jxpath.CompiledExpression.getValue(JXPathContext) and I too am seeing hundreds of threads stuck trying to get JXPathIntrospector.getBeanInfo. I notice only 1.3 is available from the website. When is 1.4 available to the public? 293 threads with trace:Rate States: {RUNNABLE=293} Stack: - java.util.HashMap.getEntry(HashMap.java:465) - java.util.HashMap.get(HashMap.java:417) - org.apache.commons.jxpath.JXPathIntrospector.getBeanInfo(JXPathIntrospector.java:101) - org.apache.commons.jxpath.ri.model.dynamic.DynamicPointerFactory.createNodePointer(DynamicPointerFactory.java:67) - org.apache.commons.jxpath.ri.model.NodePointer.newChildNodePointer(NodePointer.java:90) - org.apache.commons.jxpath.ri.model.beans.PropertyPointer.getImmediateValuePointer(PropertyPointer.java:127) - org.apache.commons.jxpath.ri.model.NodePointer.getValuePointer(NodePointer.java:238) - org.apache.commons.jxpath.ri.model.beans.PropertyIterator.getNodePointer(PropertyIterator.java:108) - org.apache.commons.jxpath.ri.axes.ChildContext.getCurrentNodePointer(ChildContext.java:56) - org.apache.commons.jxpath.ri.axes.InitialContext.(InitialContext.java:39) - org.apache.commons.jxpath.ri.compiler.LocationPath.compute(LocationPath.java:67) - org.apache.commons.jxpath.ri.compiler.CoreOperationCompare.equal(CoreOperationCompare.java:49) - org.apache.commons.jxpath.ri.compiler.CoreOperationEqual.computeValue(CoreOperationEqual.java:33) - org.apache.commons.jxpath.ri.axes.PredicateContext.nextNode(PredicateContext.java:81) - org.apache.commons.jxpath.ri.EvalContext.nextSet(EvalContext.java:322) - org.apache.commons.jxpath.ri.axes.ChildContext.getSingleNodePointer(ChildContext.java:72) - org.apache.commons.jxpath.ri.compiler.Path.searchForPath(Path.java:183) - org.apache.commons.jxpath.ri.compiler.Path.getSingleNodePointerForSteps(Path.java:159) - org.apache.commons.jxpath.ri.compiler.LocationPath.computeValue(LocationPath.java:82) - org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:314) - org.apache.commons.jxpath.ri.JXPathCompiledExpression.getValue(JXPathCompiledExpression.java:57) > Concurrent access on hashmap of JXPathIntrospector > -- > > Key: JXPATH-152 > URL: https://issues.apache.org/jira/browse/JXPATH-152 > Project: Commons JXPath > Issue Type: Bug >Affects Versions: 1.3 > Environment: Java5, Windows/AIX >Reporter: pleutre >Assignee: Matt Benson >Priority: Minor > Fix For: 1.4 > > Original Estimate: 24h > Remaining Estimate: 24h > > JXPathIntrospector.registerDynamicClass method can be called in static part > of classes. > If two classes A & B try to registerDynamicClass in the same time a > concurrent access exception can append on hashmap of JXPathIntrospector. > Replace hashmap by concurrent hashmap or synchronized access to these > hashmaps. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (JXPATH-152) Concurrent access on hashmap of JXPathIntrospector
[ https://issues.apache.org/jira/browse/JXPATH-152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13257293#comment-13257293 ] Naozumi Taromaru commented on JXPATH-152: - > correction method 3: (JDK1.3 compatible. but contrary to usage.) Sorry, it has problem. ArrayIndexOutOfBoundsException may occur. The problem did not occur in the case of Sun(Oracle) JDK5. result of get method: * return null * return value object But, the problem occured in the case of Sun(Oracle) JDK6. result of get method: * return null * return value object * throw ArrayIndexOutOfBoundsException > Concurrent access on hashmap of JXPathIntrospector > -- > > Key: JXPATH-152 > URL: https://issues.apache.org/jira/browse/JXPATH-152 > Project: Commons JXPath > Issue Type: Bug >Affects Versions: 1.3 > Environment: Java5, Windows/AIX >Reporter: pleutre >Assignee: Matt Benson >Priority: Minor > Fix For: 1.4 > > Original Estimate: 24h > Remaining Estimate: 24h > > JXPathIntrospector.registerDynamicClass method can be called in static part > of classes. > If two classes A & B try to registerDynamicClass in the same time a > concurrent access exception can append on hashmap of JXPathIntrospector. > Replace hashmap by concurrent hashmap or synchronized access to these > hashmaps. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (JXPATH-152) Concurrent access on hashmap of JXPathIntrospector
[ https://issues.apache.org/jira/browse/JXPATH-152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13220937#comment-13220937 ] Naozumi Taromaru commented on JXPATH-152: - Collections.synchronizedMap is thread safe method. However, since these HashMap are referred to frequently, it becomes a bottleneck by the method of synchronizedMap's lock in a multi-core CPU (or multi CPU) environment. I recommend correcting by one of the following methods. These methods can perform Map#get concurrently. * Since byInterface resembles byClass, byInterface omits. Before correction: (Before #1293412 modification.) private static HashMap byClass = new HashMap(); ... byClass.put(...); ... beanInfo = (JXPathBeanInfo) byClass.get(...); correction method 1: (Easy) private static Map byClass = ConcurrentHashMap(); ... byClass.put(...); ... beanInfo = (JXPathBeanInfo) byClass.get(...); * ConcurrentHashMap : java.util.concurrent.ConcurrentHashMap (JDK5 or later) The feature of the method 1: * Unlike JXPath-1.3, required JDK5 or later. * Unlike JXPath-1.3, if key or value is null, NullPointerException occur. (If you maintain the compatibility when key or value is null value, please see method 2.) correction method 2: (Specification is full compatible) private static HashMap byClass = new HashMap(); private static final ReentrantReadWriteLock byClassReadWriteLock = new ReentrantReadWriteLock(); private static final Lock byClassReadLock = byClassReadWriteLock.readLock(); private static final Lock byClassWriteLock = byClassReadWriteLock.writeLock(); ... byClassWriteLock.lock(); try { byClass.put(...); } finally { byClassWriteLock.unlock(); } ... byClassReadLock.lock(); try { beanInfo = (JXPathBeanInfo) byClass.get(...); } finally { byClassReadLock.unlock(); } * ReentrantReadWriteLock : java.util.concurrent.locks.ReentrantReadWriteLock (JDK5 or later) * Lock : java.util.concurrent.locks.Lock (JDK5 or later) please see http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/locks/ReentrantReadWriteLock.html "RWDictionary" example. The feature of the method 2: * Unlike JXPath-1.3, required JDK5 or later. * Like JXPath-1.3, null can be used for key or value. correction method 3: (JDK1.3 compatible. but contrary to usage.) private static HashMap byClass = new HashMap(); ... synchronized (byClass) { byClass.put(...); } ... beanInfo = (JXPathBeanInfo) byClass.get(...); if (beanInfo == null) { // not mapping, null mapping, or when byClass is being expanded. synchronized (byClass) { beanInfo = (JXPathBeanInfo) byClass.get(...); } } * Although it is contrary to usage, this method can be used if it is java.util.HashMap, using method are "put" "get" only. (At least in the case of Sun(Oracle) JDK.) The feature of the method 3: * Like JXPath-1.3, JDK1.3 compatible. * Like JXPath-1.3, null can be used for key or value. * It is contrary to the following description of HashMap's API document. "If multiple threads access this map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally." (http://docs.oracle.com/javase/1.5.0/docs/api/java/util/HashMap.html) > Concurrent access on hashmap of JXPathIntrospector > -- > > Key: JXPATH-152 > URL: https://issues.apache.org/jira/browse/JXPATH-152 > Project: Commons JXPath > Issue Type: Bug >Affects Versions: 1.3 > Environment: Java5, Windows/AIX >Reporter: pleutre >Assignee: Matt Benson >Priority: Minor > Fix For: 1.4 > > Original Estimate: 24h > Remaining Estimate: 24h > > JXPathIntrospector.registerDynamicClass method can be called in static part > of classes. > If two classes A & B try to registerDynamicClass in the same time a > concurrent access exception can append on hashmap of JXPathIntrospector. > Replace hashmap by concurrent hashmap or synchronized access to these > hashmaps. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (JXPATH-152) Concurrent access on hashmap of JXPathIntrospector
[ https://issues.apache.org/jira/browse/JXPATH-152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13214456#comment-13214456 ] Naozumi Taromaru commented on JXPATH-152: - I think that this issue is a critical bug. For example, if the following code(an ordinary code) is executed in a multithread environment, all threads hang-up(infinity loop) occurs in the worst case. JXPathContext context = JXPathContext.newContext(target); Iterator ite = context.iteratePointers(requestXpath); while (ite.hasNext()) { Pointer p = (Pointer) ite.next(); ... } Thread-1 use JXPathContext instance-1. Thread-2 use JXPathContext instance-2. However, Thread-1 and Thread-2 may execute JXPathIntrospector#getBeanInfo (static method) concurrently. JXPathIntrospector#getBeanInfo execute "byClass.put(beanClass, beanInfo);". ("byClass" is HashMap in static field) That is, Thread-1 and Thread-2 may execute HashMap#put concurrently. Thread-1 and Thread-2 use same HashMap instance (in static field). In the worst case, Thread-1 and Thread-2 expand HashMap capacity concurrently. Then, the structure of HashMap is broken. If a thread use broken HashMap's method(get, put, etc...), the thread execute infinity loop in HashMap. If HashMap(byClass) is broken, Thread-1 use JXPathContext ... infinity loop Thread-2 use JXPathContext ... infinity loop Thread-3 use JXPathContext ... infinity loop ... As a result, all threads hang-up(infinity loop). > Concurrent access on hashmap of JXPathIntrospector > -- > > Key: JXPATH-152 > URL: https://issues.apache.org/jira/browse/JXPATH-152 > Project: Commons JXPath > Issue Type: Bug >Affects Versions: 1.3 > Environment: Java5, Windows/AIX >Reporter: pleutre >Priority: Minor > Original Estimate: 24h > Remaining Estimate: 24h > > JXPathIntrospector.registerDynamicClass method can be called in static part > of classes. > If two classes A & B try to registerDynamicClass in the same time a > concurrent access exception can append on hashmap of JXPathIntrospector. > Replace hashmap by concurrent hashmap or synchronized access to these > hashmaps. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira