commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vladimir Zhilin (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (DBUTILS-140) Thread safety problem in BeanProcessor
Date Tue, 24 Jul 2018 07:25:00 GMT

     [ https://issues.apache.org/jira/browse/DBUTILS-140?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Vladimir Zhilin updated DBUTILS-140:
------------------------------------
    Description: 
Sometimes Exception occurs when method QueryRunner.query() is called with BeanHandler. 
{code:java}
// works fine with N = 1
int N = 8;
ExecutorService execs = Executors.newFixedThreadPool(N);
Runnable task = () -> {
    try {
        Data bean = runner.query("select id from test_table", new BeanHandler<Data>(Data.class));
        System.out.println("result: " + bean);
    } catch (Exception e) {
        e.printStackTrace();
    }
};

for (int i = 0; i < N; i++) {
    execs.submit(task);
}
{code}
Full code is attached: dbutils-bug-test.zip

 

 
{code:java}
java.util.NoSuchElementException
at sun.misc.CompoundEnumeration.nextElement(CompoundEnumeration.java:59)
at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:357)
at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393)
at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474)
at org.apache.commons.dbutils.BeanProcessor.callSetter(BeanProcessor.java:300)
at org.apache.commons.dbutils.BeanProcessor.populateBean(BeanProcessor.java:275)
at org.apache.commons.dbutils.BeanProcessor.populateBean(BeanProcessor.java:239)
at org.apache.commons.dbutils.BeanProcessor.toBean(BeanProcessor.java:154)
at org.apache.commons.dbutils.BasicRowProcessor.toBean(BasicRowProcessor.java:123)
at org.apache.commons.dbutils.handlers.BeanHandler.handle(BeanHandler.java:80)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:388)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:347)
at EntryPoint$1.run(EntryPoint.java:26){code}
 

Seems like there is a race when propertyHandlers field in BeanProcessor is accessing from
multiple threads. Iterating ServiceLoader is not thread-safe.

 

  was:
Sometimes Exception occurs when method QueryRunner.query() is called with BeanHandler. 
{code:java}
// works fine with N = 1
int N = 8;
ExecutorService execs = Executors.newFixedThreadPool(N);
Runnable task = () -> {
    try {
        Data bean = runner.query("select id from test_table", new BeanHandler<Data>(Data.class));
        System.out.println("result: " + bean);
    } catch (Exception e) {
        e.printStackTrace();
    }
};

for (int i = 0; i < N; i++) {
    execs.submit(task);
}
{code}
Full code is attached: dbutils-bug-test.zip

 

Exception

 
{code:java}
java.util.NoSuchElementException
at sun.misc.CompoundEnumeration.nextElement(CompoundEnumeration.java:59)
at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:357)
at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393)
at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474)
at org.apache.commons.dbutils.BeanProcessor.callSetter(BeanProcessor.java:300)
at org.apache.commons.dbutils.BeanProcessor.populateBean(BeanProcessor.java:275)
at org.apache.commons.dbutils.BeanProcessor.populateBean(BeanProcessor.java:239)
at org.apache.commons.dbutils.BeanProcessor.toBean(BeanProcessor.java:154)
at org.apache.commons.dbutils.BasicRowProcessor.toBean(BasicRowProcessor.java:123)
at org.apache.commons.dbutils.handlers.BeanHandler.handle(BeanHandler.java:80)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:388)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:347)
at EntryPoint$1.run(EntryPoint.java:26){code}
 

Seems like there is a race when propertyHandlers field in BeanProcessor is accessing from
multiple threads. Iterating ServiceLoader is not thread-safe.

 


> Thread safety problem in BeanProcessor
> --------------------------------------
>
>                 Key: DBUTILS-140
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-140
>             Project: Commons DbUtils
>          Issue Type: Bug
>    Affects Versions: 1.7
>         Environment: jdk1.8.0_171
>            Reporter: Vladimir Zhilin
>            Priority: Major
>         Attachments: dbutils-bug-test.zip
>
>
> Sometimes Exception occurs when method QueryRunner.query() is called with BeanHandler. 
> {code:java}
> // works fine with N = 1
> int N = 8;
> ExecutorService execs = Executors.newFixedThreadPool(N);
> Runnable task = () -> {
>     try {
>         Data bean = runner.query("select id from test_table", new BeanHandler<Data>(Data.class));
>         System.out.println("result: " + bean);
>     } catch (Exception e) {
>         e.printStackTrace();
>     }
> };
> for (int i = 0; i < N; i++) {
>     execs.submit(task);
> }
> {code}
> Full code is attached: dbutils-bug-test.zip
>  
>  
> {code:java}
> java.util.NoSuchElementException
> at sun.misc.CompoundEnumeration.nextElement(CompoundEnumeration.java:59)
> at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:357)
> at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393)
> at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474)
> at org.apache.commons.dbutils.BeanProcessor.callSetter(BeanProcessor.java:300)
> at org.apache.commons.dbutils.BeanProcessor.populateBean(BeanProcessor.java:275)
> at org.apache.commons.dbutils.BeanProcessor.populateBean(BeanProcessor.java:239)
> at org.apache.commons.dbutils.BeanProcessor.toBean(BeanProcessor.java:154)
> at org.apache.commons.dbutils.BasicRowProcessor.toBean(BasicRowProcessor.java:123)
> at org.apache.commons.dbutils.handlers.BeanHandler.handle(BeanHandler.java:80)
> at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:388)
> at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:347)
> at EntryPoint$1.run(EntryPoint.java:26){code}
>  
> Seems like there is a race when propertyHandlers field in BeanProcessor is accessing
from multiple threads. Iterating ServiceLoader is not thread-safe.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message