Synchronize("Cache_Group") part gets skipped , why is it so?
Asked Answered
A

2

44

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 .

Azobenzene answered 1/6, 2015 at 13:2 Comment(4)
Can you provide some sample code that produce the incorrect behavior?Exon
Please provide more information or sample code for getting the solution.Deepseated
Doesn't seems like an Android question to me. Is it possible this is an MSSQL server question?Pettish
How this question came up with so many upvotes? I'm clearly not the only one who could not understand what's this question is about at allEugene
D
2
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

Doyon answered 8/9, 2015 at 22:26 Comment(0)
M
1

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!

Meetinghouse answered 4/1, 2017 at 10:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.