• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.lang.ArrayIndexOutOfBoundException: -1 error while using selectNodeList(contextNode,string)

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Guyz,

we have implemented the XML parsing using the Apache XML API (xalan.jar) in our web application and in the production environment.

Some times when load on the server is heavy we are getting the "ArrayIndexOutOfBoundException -1" error messages during the XML parsing process and this is leading to the severe server problems. The error messages are appeared when huge number of users are accessing the application at the same time and number of instances are accessing the "selectNodeList(contextnode, string)" method of CachedXPathAPI" class.

Upon rigorous investigation I am able to reproduce this error in a sample java program in Eclipse.

I designed the java program very similar to our program in the application and tested it in the ecilipse. To replicate the scenario I implemented multi threading and created 100 threads and accessed the method selectNodeList(contextNode,string) simultaniously.

The error is as below



This error is not reproducible always. similarly in our production environment also we are getting this message when server load is heavy.

My sample program is as below:



The XML file content has this data



The class "com.philips.sc.impulse.util.xml.XMLHelper" is our own proprietery class file

How to solve this problem. Can anybody help us here please...
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks to me like the CachedXPathAPI object is not thread-safe. Have you tried synchronizing access to it?
 
Hemanth Kumar Simhadri
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

You are correct. It was mentioned in the CachedXPathAPI class API that :

"Any particular instance of CachedXPathAPI must not be operated upon by multiple threads without synchronization."

The methods of CachedXPathAPI class are not thread safe. By synchronizing the code it worked fine for any number of threads. The execution is always successful

The code should be as below. This is working good




I have to try implementing the same in our production server and let you know the result
 
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic