Giter Club home page Giter Club logo

Comments (5)

j256 avatar j256 commented on July 17, 2024

This is pretty wild. What database are you using? Are you always updating items?

from ormlite-android.

vicfaith avatar vicfaith commented on July 17, 2024

Hi, It's an Android app. a single assetDao via OrmLiteSqliteOpenHelper across the app.
createOrUpdate always returns success but no rows in the DB.. it's quite weird.

before update
1 a
2 b
3 c
4 d
5 f
...

after update
1 a'
2 b'
5 f'
...

// below code is run by around 10 threads at the same time.
// it parses data (tens of assets) and always update same table via the assetDao.
mAssetDao.callBatchTasks(new Callable() {
@OverRide
public Object call() throws Exception {
for (int i = 0; i < jsonAssets.length(); i++) {
JSONObject jsonAsset = jsonAssets.getJSONObject(i);
Asset asset = new Asset();
parseAsset(asset, jsonAsset);
mAssetDao.createOrUpdate(asset);
}
return null;
}
});

from ormlite-android.

j256 avatar j256 commented on July 17, 2024

Sorry for the delay. Can you write a junit test that reproduces this? We are getting ready to [finally] push 4.49 and I'd like to make sure this isn't an issue.

from ormlite-android.

j256 avatar j256 commented on July 17, 2024

Ok, I understand this now and it makes sense. Multiple threads cannot use the callBatchTasks(...) at the same time because there is a single database connection and the transactions are getting screwed up. I just added the following to the javadocs:

NOTE: Depending on your underlying database implementation and whether or not you are working with a single database connection, you may need to synchronize around calls to this method otherwise the database transactions that are used may clash when called simultaneously from multiple threads. You may also need to synchronize other calls to transactions and dao.setAutoCommit(...).

from ormlite-android.

j256 avatar j256 commented on July 17, 2024

Related to #34

from ormlite-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.