-
Bug
-
Resolution: Not an Issue
-
P3
-
6
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.6.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-rc-b63) Java HotSpot(TM) Client VM (build 1.6.0-rc-b63, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Cross posting Wrom: RCLBDXRQBGJSNBOHMKHJYFMYXOEAIJJPHSCRTNHGSWZIDREXCAX
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I ran into an issue when running the StAX parser in a multi-threaded
environment. The environment shares one single instance of XMLInputFactory and
the reuse-instance property is enabled (ie the default setting). When creating
and using XMLStreamReader instances from that singleton factory object, I get
various errors (Scanner State 7 not Recognized, ArrayIndexOutOfBoundsException...).
When I 1) set the reuse-instance property to false or 2) don't close the
XMLStreamReader instances, everything seems to work correctly. Now, I would an
of these options introduces a performance penalty as you can't reuse these
instances and therefor have to create new XMLStreamReader instances when one is
requested.
Is this behaviour expected?
Below is a small Java program reproducing the issue.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
See 'Steps to Reproduce'
ACTUAL -
See 'Steps to Reproduce'
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class StAXThreading implements Runnable {
static int nrOfThreads = 10;
static XMLInputFactory xif = XMLInputFactory.newInstance();
static boolean ReuseInstance = true;
static boolean CloseInstance = true;
static URL xmlFile;
public static void main(String[] args) {
try {
xif.setProperty("reuse-instance", Boolean.valueOf(ReuseInstance));
xmlFile = xmlFile = new File("W:/XQuery/xqqa/creates/xml/ITEMS.xml").toURL();
for (int ix = 0; ix < nrOfThreads; ix++) {
Thread t = new Thread(new StAXThreading(), "StAX parsing thread #" + ix);
t.setDaemon(false);
t.start();
}
System.out.println(Thread.currentThread().getName() + ": done");
} catch (Exception e) {
System.err.println(Thread.currentThread().getName() + ": exception:");
e.printStackTrace();
}
}
long begin, end;
public void run() {
try {
begin = System.currentTimeMillis();
do {
XMLStreamReader xsr = xif.createXMLStreamReader(xmlFile.openStream());
while (xsr.hasNext()) {
xsr.next();
}
if (CloseInstance) {
xsr.close();
}
end = System.currentTimeMillis();
} while ((end - begin) < 15000);
} catch (Exception e) {
System.err.println(Thread.currentThread().getName() + ": exception:");
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName() + ": done");
}
}
---------- END SOURCE ----------
java version "1.6.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-rc-b63) Java HotSpot(TM) Client VM (build 1.6.0-rc-b63, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Cross posting Wrom: RCLBDXRQBGJSNBOHMKHJYFMYXOEAIJJPHSCRTNHGSWZIDREXCAX
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I ran into an issue when running the StAX parser in a multi-threaded
environment. The environment shares one single instance of XMLInputFactory and
the reuse-instance property is enabled (ie the default setting). When creating
and using XMLStreamReader instances from that singleton factory object, I get
various errors (Scanner State 7 not Recognized, ArrayIndexOutOfBoundsException...).
When I 1) set the reuse-instance property to false or 2) don't close the
XMLStreamReader instances, everything seems to work correctly. Now, I would an
of these options introduces a performance penalty as you can't reuse these
instances and therefor have to create new XMLStreamReader instances when one is
requested.
Is this behaviour expected?
Below is a small Java program reproducing the issue.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
See 'Steps to Reproduce'
ACTUAL -
See 'Steps to Reproduce'
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class StAXThreading implements Runnable {
static int nrOfThreads = 10;
static XMLInputFactory xif = XMLInputFactory.newInstance();
static boolean ReuseInstance = true;
static boolean CloseInstance = true;
static URL xmlFile;
public static void main(String[] args) {
try {
xif.setProperty("reuse-instance", Boolean.valueOf(ReuseInstance));
xmlFile = xmlFile = new File("W:/XQuery/xqqa/creates/xml/ITEMS.xml").toURL();
for (int ix = 0; ix < nrOfThreads; ix++) {
Thread t = new Thread(new StAXThreading(), "StAX parsing thread #" + ix);
t.setDaemon(false);
t.start();
}
System.out.println(Thread.currentThread().getName() + ": done");
} catch (Exception e) {
System.err.println(Thread.currentThread().getName() + ": exception:");
e.printStackTrace();
}
}
long begin, end;
public void run() {
try {
begin = System.currentTimeMillis();
do {
XMLStreamReader xsr = xif.createXMLStreamReader(xmlFile.openStream());
while (xsr.hasNext()) {
xsr.next();
}
if (CloseInstance) {
xsr.close();
}
end = System.currentTimeMillis();
} while ((end - begin) < 15000);
} catch (Exception e) {
System.err.println(Thread.currentThread().getName() + ": exception:");
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName() + ": done");
}
}
---------- END SOURCE ----------