Document save with synchronized lock



For document creation and save there is synchronized (lock) in class
that create a lock on object, is preventing Document save frequently if previous is under progress.
Can we resolve this problem for saving document in fast sequence


Have you done profiling to reveal that this is a bottleneck? If not then I cannot recommend changing anything in there as it will eliminate thread safety guarantees.


Yes My Dear borrrden, my requirement is to create and save a new document for rapidly clicks
by use. But i am locked here.
Can you please suggest any solution.

Class name

// The main save method.
private boolean save(Document document, boolean deletion, ConcurrencyControl concurrencyControl) throws CouchbaseLiteException {

Line of code synchronized (lock) {

Line no 1001


If the only thing that is happening is user clicks to save a new document, I doubt two things:

  1. I don’t see how the lock could ever be contended since only a single thread is calling the save
  2. I don’t see how the user could possibly click fast enough to cause a backlog unless they were clicking constantly for fun maybe

What tools have you profiled with to narrow down the cause of the slowness to this line?


Dear Borrrden , may be this statement is for maintain atomicity or ConcurrencyControl.
but in my project there are product list and user is just need to select them and add into cart in very fast manner, that why we need to create a document for each one for each click.

right now i am just using Schedulers with RX java for background calling but i am unable to over come this jerk in my clicks .

if i comment //
this line of code then every thing is working very smoothly .


I imagine there are many factors at play so unless you have evidence that it is that line in particular that is causing the problem (the lock) then I cannot support removing it. You should use profiling tools to find the hot spots in the code.