j256 / ormlite-android

ORMLite Android functionality used in conjunction with ormlite-core
http://ormlite.com/
ISC License
1.59k stars 367 forks source link

IllegalStateException: attempt to re-open an already-closed object #112

Closed me73123 closed 5 years ago

me73123 commented 5 years ago

I have an error "IllegalStateException: attempt to re-open an already-closed object" in multi thread by android 9.0.

I closed the connectionSource in each query. like this:

ConnectionSource cs = cf.getConnectionSource();
try {
    UserDao userDao = new UserDao(cs);
    userDao.deleteAll();
} catch (Exception e) {
    throw e;
} finally {
    try {
        cs.close();
    } catch (SQLException e) {
        logger.error("Exception:" + e);
    }
}

Any ideas?

noordawod commented 5 years ago

Why are you closing the connection source?

me73123 commented 5 years ago

The connection will be closed after each query because the connection source may not be used later.

me73123 commented 5 years ago

I solved this problem. I closed the connectionSource before first get connection source.

j256 commented 5 years ago

Any idea why the old version didn't suffer from this problem?

me73123 commented 5 years ago

I just reconfirmed whether an old version of android has encountered this problem. It seems that the same problem will arise.

siyinngduo commented 5 years ago

When can close be called?