I am trying to spawn a thread for just 1 method. Im getting an IllegalStateException
(see below). What this method does it accept a Connection to a database and the database name, and it will generate XML from it. (That part works I am just trying to make it go faster with a new thread because I have multiple XML files to create.
Thread table = new Thread(new Runnable() {
public void run() {
try {
System.out.println("starting");
tableXml(tableConn, dbName);
System.out.println("ending");
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
table.start();
Exception:
java.lang.IllegalStateException: Current state = RESET, new state = FLUSHED
at java.nio.charset.CharsetEncoder.throwIllegalStateException(CharsetEncoder.java:951)
at java.nio.charset.CharsetEncoder.flush(CharsetEncoder.java:640)
at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:769)
at com.informix.lang.JavaToIfxType.doConversion(JavaToIfxType.java:841)
at com.informix.lang.JavaToIfxType.JavaToIfxChar(JavaToIfxType.java:145)
at com.informix.jdbc.IfxVarChar.toString(IfxVarChar.java:247)
at com.informix.jdbc.IfxResultSet.getString(IfxResultSet.java:742)
at com.informix.jdbc.IfxResultSet.getString(IfxResultSet.java:785)
at org.apache.commons.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:225)
at com.test.ex.ExportTask$1.run(ExportTask.java:151)
at java.lang.Thread.run(Thread.java:662)
The line of code that is causing the exception is a resultSet.executeQuery();
So the question is: what am I doing wrong?
Thanks for your help, let me know if you need information
It seems that the problem is because your code is not thread safe. Try giving each new thread that is spawned its own connection instead of sharing a reference of a single connection between all threads in your application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With