@@ -177,22 +177,34 @@ public synchronized void execute(int cursorIdx, Object[] parms)
177177 // we need to lock the execute method to avoid concurrency issues.
178178 // for example, the postExecute method (select changes()) cause exception in Android SQLite.
179179 // it happends with execute sql statements like from diferent threads, like using procedures submit.
180- AndroidLog .debug ("execute cursorIdx : " + cursorIdx );
181- long timeStampStart = System .currentTimeMillis ();
182- lockExecute .lock ();
183- long timeStampLock = System .currentTimeMillis ();
184- AndroidLog .debug ("START execute afterlock cursorIdx: " + cursorIdx + " Waiting time ms: " + (timeStampLock - timeStampStart ));
185- try
186- {
187- // execute the cursor with the parameters.
188- execute (cursorIdx , parms , true );
180+ Cursor cursor = cursors [cursorIdx ];
181+ if (cursor instanceof UpdateCursor ) // if the cursor is an UpdateCursor, we need to lock the execute method.
182+ {
183+ AndroidLog .debug ("execute UpdateCursor cursorIdx : " + cursorIdx );
184+ long timeStampStart = System .currentTimeMillis ();
185+ lockExecute .lock ();
186+ long timeStampLock = System .currentTimeMillis ();
187+ AndroidLog .debug ("START execute UpdateCursor afterlock cursorIdx: " + cursorIdx + " Waiting time ms: " + (timeStampLock - timeStampStart ));
188+ try
189+ {
190+ // execute the cursor with the parameters.
191+ execute (cursorIdx , parms , true );
192+ }
193+ finally
194+ {
195+ lockExecute .unlock ();
196+ }
197+ long timeStampEnd = System .currentTimeMillis ();
198+ AndroidLog .debug ("END execute UpdateCursor cursorIdx: " + cursorIdx + " Execute time ms: " + (timeStampEnd - timeStampLock ));
189199 }
190- finally
200+ else
191201 {
192- lockExecute .unlock ();
202+ // if the cursor is not an UpdateCursor, we can execute it without locking.
203+ long timeStampStart = System .currentTimeMillis ();
204+ execute (cursorIdx , parms , true );
205+ long timeStampEnd = System .currentTimeMillis ();
206+ AndroidLog .debug ("END execute cursorIdx: " + cursorIdx + " Execute time ms: " + (timeStampEnd - timeStampStart ));
193207 }
194- long timeStampEnd = System .currentTimeMillis ();
195- AndroidLog .debug ("END execute cursorIdx: " + cursorIdx + " Execute time ms: " + (timeStampEnd - timeStampLock ));
196208 }
197209 else
198210 {
0 commit comments