android - should - Synchronize(“Cache_Group”) part gets skipped,why is it so?




turn on auto sync android (2)

if your doing something like this:

sychronized("Cache_Group")

then your creating a string every time you want to syncronize which means your syncronizing different Objects every time, what you need is to syncronize one variable between functions

example:

public class test{
    final Object lock = new Object;

    public void apple(){
        sychronized(lock ){
            ...
        }
    }

    public void orange(){
        sychronized(lock ){
            ...
        }
    }
}

TIP: example above shows locking inside a class, if you want to lock between classes then your lock Object should be static/ above these classes or global, but beware from deadlocking your self!

https://code.i-harness.com

I am trying to figure out that my synchronize("Group_Name") gets skipped if I try to sync different values through it , why is it so .

Consider the following issue .

I have a SyncGroup named - "Group1" in which I have a MBO named "MBOGroup1" in which I have attributes "name" , "password" , "codeCheck" . I fetch data and extract on attribute as "releaseCode"

Now I have another SyncGroup named - "GroupSub1" in which I have a MBO named "MBOSubGroup1" in which I pass attributes "releaseCode" I get some result .

The condition is as follows

If I get multiple rows for "MBOGroup1" , I put a for loop for "GroupSub1" and pass each "releaseCode" data to "GroupSub1" and extract result

Most of the times it happens that some releaseCode gets skipped and I get incorrect "result" for "GroupSub1" why is it so ?? Is it due to for loop executing faster than synchronize() word or something else like CacheGroup Policies as OnDemand and time as 10seconds

Kindly help .

As there are data in which I need to put more than 4 for loops in which my future syncGroup results depends on results fetched from previous one .


sychronized("Cache_Group")

First thing that comes to mind is that sychronizing on a string is useless.

sychronized locks access to a block based on the given reference not the value. Using a "String" defeats this purpose because strings are immutable and calling synchronized("Cache_Group") twice will construct 2 strings with 2 different references, allowing the second iteration to break the intended lock.

EDIT: @see ReentrantLock for better access control





synchronization