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
Developer
zinzinzan
Posts: 90
Registered: ‎04-03-2012
My Carrier: movilnet

Database concurrency Problem

[ Edited ]

hi there,

  i am using a database in my  alternate entry point,  and when the user callthe GUI app some times i am getting a null pointer exeption just when i install the app , i suspect is due both app try use DB at the same time what is the best aproach to avoid this. thx

 

 

SDK 6.0

Please use plain text.
Developer
zinzinzan
Posts: 90
Registered: ‎04-03-2012
My Carrier: movilnet

Re: Database concurrency Problem

HELP

Please use plain text.
Developer
zinzinzan
Posts: 90
Registered: ‎04-03-2012
My Carrier: movilnet

Re: Database concurrency Problem

:Helpsmilie:

Please use plain text.
New Developer
chrisjohnhandy
Posts: 3
Registered: ‎11-21-2012
My Carrier: 3

Re: Database concurrency Problem

I have not yet had to deal with a database shared between 2 apps (if that is what you are trying to do).

 

At the moment blackberry implementation of sqlLite only supports 1 write connection. However can support multiple read connections (if all one app needs to do is read then open use open with the read only parameter):
http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/database/DatabaseFactory.html

Otherwise you will probably have to use a shared resource as a lock or race condition, I would suggest an object in the persistant store. And make sure that only one of the apps has an open connection at a time with it.

 

Hope you find something usefull in here :/

Please use plain text.
Developer
zinzinzan
Posts: 90
Registered: ‎04-03-2012
My Carrier: movilnet

Re: Database concurrency Problem

hummm sounds good i will try with  the persisten store thx

Please use plain text.
Developer
peter_strange
Posts: 19,526
Registered: ‎07-14-2008

Re: Database concurrency Problem

Your problem I would almost guarantee is nothing to do with concurrent access to the database.  I am betting you have a static reference and you expect that because one app (say the one started at device startup) has set this static variable, the other app should see it. 

 

For static variables this is unfortunately not true when the there are two different applications involved.

 

So basically if you want two applications sharing the same Persistent Store Object (which is perfectly supported and will work correctly), then both application have to go to persistent store and get the Object.  They should save a reference to that Object.  But everything should be accessed through this Object.  Do not expect static variables from one application to be useful by the other one.

 

Hope this makes sense. 

Please use plain text.
Developer
zinzinzan
Posts: 90
Registered: ‎04-03-2012
My Carrier: movilnet

Re: Database concurrency Problem

hi peter,

   well i put in the run time store all my shared static variables =), anyway i will check but i have to tell u when u put sleep the background app ( started at device startup )   in the first case just when app isstalled and ppl chose run it the null pointer is  gone. ( sleep = 60 sec ) 

Please use plain text.
Developer
peter_strange
Posts: 19,526
Registered: ‎07-14-2008

Re: Database concurrency Problem

Going to be honest here, putting sleep in an event driven system just makes me think that you are not developing things correctly......

Please use plain text.
Developer
zinzinzan
Posts: 90
Registered: ‎04-03-2012
My Carrier: movilnet

Re: Database concurrency Problem

[ Edited ]

what u mean with event driven system? and i apologize for my english,. this was a change for prove my concurrence theory.

Please use plain text.
Developer
peter_strange
Posts: 19,526
Registered: ‎07-14-2008

Re: Database concurrency Problem

Sorry, I'm not meaning to be hard here.  Please take my comments positively.

 

Also don't worry about your English.  It is better than my <insert language of your choice>. 

 

The BlackBerry is an Event driven system.  You don't sit in the background and process something and then, when you have finished, stop.  Instead your app will listen for events, like key presses, then process these and then wait for the next event. 

 

In an event driven system, you should normally listen for an event, rather than wait and hope the event happens.

 

In your case, you seem to be saying that if you wait 60 seconds, then something happens and suddenly your variable is not null.  But the problem there is what is it that happens?  And will waiting 60 seconds always make sure that it happens, so your variable is set?

 

Here are a couple of KB articles that might help.

 

http://supportforums.blackberry.com/t5/Java-Development/Create-a-singleton-using-the-RuntimeStore/ta...

I suspect you have seen this.

 

http://supportforums.blackberry.com/t5/Java-Development/Write-safe-initialization-code/ta-p/444795

Perhaps this is your problem with your background code?

Please use plain text.