Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch Executor is thread safe or not #68

Open
rahulsrivastava71 opened this issue Sep 3, 2015 · 4 comments
Open

Batch Executor is thread safe or not #68

rahulsrivastava71 opened this issue Sep 3, 2015 · 4 comments

Comments

@rahulsrivastava71
Copy link

Dear Eugene,
I have one query related to Batch executor that , is your batch executor thread safe or not ,
as we have to use synchronised block on that executor or not.

@valchkou
Copy link
Owner

valchkou commented Sep 3, 2015

Not sure how you intend to use it.
correct use sample:

  1. mappingSession is threadsafe and you can reuse it in multiple threads
// new batch statement created each time
mappingSession.withBatch()
            .save(obj1)
            .delete(obj2)
            .execute();
  1. you can reuse batch object as soon as you don't modify it, don't add statements
// initialize batch  
BatchExecutor batch = mappingSession
    .withBatch()
    .save(obj1)
    .(obj2);        

// execute it from multiple threads
batch.execute();    

@rahulsrivastava71
Copy link
Author

suppose if my mappingSession is singleton and i am trying to access two
quries from two different locations using the same session (singleton
object) one is simple query and other is batch then i require synchronised
block on executor or mappingSession ,
But you are saying that mappingSession itself is thread safe.
So what is the exact way to do it.

On Thu, Sep 3, 2015 at 11:41 PM, Eugene [email protected] wrote:

Not sure how you intend to use it.
correct use sample:

  1. mappingSession is threadsafe and you can reuse it in multiple threads

// new batch statement created each time
mappingSession.withBatch()
.save(obj1)
.delete(obj2)
.execute();

  1. you can reuse batch object as soon as you don't modify it, don't add
    statements

// initialize batch BatchExecutor batch = mappingSession
.withBatch()
.save(obj1)
.(obj2);
// execute it from multiple threads
batch.execute();


Reply to this email directly or view it on GitHub
#68 (comment)
.

@valchkou
Copy link
Owner

valchkou commented Sep 4, 2015

you can use same mappingSession from multiple threads, no need to synchronize it.

@rahulsrivastava71
Copy link
Author

and if i am modifieying the batch then also i dont need to sysnchronise it.

On Fri, Sep 4, 2015 at 10:25 AM, Eugene [email protected] wrote:

you can use same mappingSession from multiple threads, no need to
synchronize it.


Reply to this email directly or view it on GitHub
#68 (comment)
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants