Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
henryci
Posts: 23
Registered: ‎01-01-2009
My Device: Not Specified

How to synchronize access to the persistent store?

I am developing a library that stores data in the persistent store.  Because it is a library, it is possible for two apps running simultaneously to both attempt to access the p-store at the same instant.  I can't find a global lock object on the device, is there some way to get a lock to the store, or should I switch to files or some other, lockable, resource?

 

-- Henry 

Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: How to synchronize access to the persistent store?

I assume that you have some sort class that wraps the access to the persistent store?

 

If so, just synchronize the the data retrieval method.

 

 

 

 

New Developer
henryci
Posts: 23
Registered: ‎01-01-2009
My Device: Not Specified

Re: How to synchronize access to the persistent store?

But does that work if I have two instances of the class in totally seperate applications running at the same time?  My understanding was that synchronized is per-object.  So two different objects could both try and access the store at the same time.

 

-- Henry 

Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: How to synchronize access to the persistent store?

Gotcha.

 

How about creating some type of semaphore or "latch" object in the runtime store?

 

See RuntimeStore in the API docs.

 

 

New Developer
henryci
Posts: 23
Registered: ‎01-01-2009
My Device: Not Specified

Re: How to synchronize access to the persistent store?

My hope was that something like that would be provided.  Looks like it's time to bust out those college textbooks. :smileyhappy:

 

-- Henry

Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: How to synchronize access to the persistent store?

PersistentStore does have a public static Object getSynchObject()

method which I would have thought would return an object global to the

JVM but that may not be the case.

 

Presumably the gui ends up having to be synchronized across apps too,

I don't think this is impossible. I guess you could call thjis method in the debugger from the

two competing apps and see if it returns the same addresss.