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
tmountain
Posts: 90
Registered: ‎02-27-2009
My Device: Not Specified

PersistentStore Problem

Hi, I'm running into an issue regarding the PersistentStore in my app. When my app starts, it fires up a background thread to establish a session with a remote webservice. The class connecting to the webservice uses a static initializer to examine user preferences and determine if they've specified a specific connection type (APN settings, Direct TCP, WAP2, etc...).

 

The issue I'm running into is that a number of users report that the initialization never finishes. Looking at their logs, I've determined that the static initializer is permanently blocking on store.getContents(). This doesn't happen for everyone, but it is a frequently occurring problem, so I know there's an issue here.

 

Is there a situation that would commonly cause getContents() to do this? There's a very small amount of data being stored in object. It's basically just login credentials and some connection info. This has been driving me crazy, so I wholeheardly appreciate any advice regarding the issue. The code is below with a comment indicating where it locks up.

 

 

static {
    Logger.log("api -> new UserAccountStore");
    _data = new UserAccountStore();
    Logger.log("api -> new get persist object");
    store = PersistentStore.getPersistentObject(PERSIST_KEY);

    synchronized (store) {
        if (store.getContents() != null) {
            Logger.log("api -> get contents");
            // BLOCKS FOREVER ON THIS CALL

            _data = (UserAccountStore) store.getContents();
        } else {
            Logger.log("api -> new user account store");
            _data = new UserAccountStore();
            Logger.log("api -> set contents");
            store.setContents(_data);
            Logger.log("api -> commit");
            store.commit();
        }

    }
}

 

 

Please use plain text.
Developer
KeniF
Posts: 131
Registered: ‎08-13-2008
My Device: Not Specified

Re: PersistentStore Problem

I honestly don't know why, but at first glance I'd ask, why getContents() twice?

 

 

UserAccountStore _data;

_data=(UserAccountStore)store.getContents();

if(_data!=null){
  //do stuff
}

else{
}

 

 

 

Please use plain text.
Developer
tmountain
Posts: 90
Registered: ‎02-27-2009
My Device: Not Specified

Re: PersistentStore Problem

I noticed that as well. I've changed it as suggested, but the problem is still happening. I'm going to attempt moving it out of the static init and into a method and see if that helps.

Please use plain text.
Developer
tmountain
Posts: 90
Registered: ‎02-27-2009
My Device: Not Specified

Re: PersistentStore Problem

The issue perists (pun pun). I've tried putting the code all over the app including the /very/ beginning. Wondering if anyone else has had this issue or can suggest why / how this could happen.

Please use plain text.
Developer
Developer
CMY
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: PersistentStore Problem

[ Edited ]

Why are you synchronizing on the store? I think it is automatically synchronized unless you are pulling data from it in two different locations. I would guess it is blocking because of the synchronized statement.

Please use plain text.
Developer
DAquilina
Posts: 587
Registered: ‎01-19-2010
My Device: BOLD 9700 OS5.0.0.x on Rogers Canada
My Carrier: Rogers

Re: PersistentStore Problem

I have 2 minor suggestions. First off, are you making sure that this process is being called once the device is started? There may be some problems if you try accessing this data before hte device has fully initialized. Put something like this at the beginning of your code and see if it helps:

 

 

public static void main (string [] args)
{
  if (Device.inStartup ())
  {
    Thread.sleep (1000);
  }
  else
  {
    //Initialize
  }
}

 

 

My other suggestion is to synchronize all access to the store and _data. There's potential for deadlock whenever reading or writing the persistent store from multiple Threads. It might be that you application is trying to access the store from a separate Thread while it is still initializing.

 

Hope that helps,

~Dom

----------------------------------------------------------------------------
chown -R us ./base
~J!NX
Please use plain text.
Developer
tmountain
Posts: 90
Registered: ‎02-27-2009
My Device: Not Specified

Re: PersistentStore Problem

Thanks for the suggestions. I will give them a try and report back.

Please use plain text.
Developer
tmountain
Posts: 90
Registered: ‎02-27-2009
My Device: Not Specified

Re: PersistentStore Problem

I've done some testing, and the issue goes away if I simply change the key being given to the getPersistentObject call. I'm wondering if frequent reads/writes to the flash memory on my users devices is exhausting the storage location associated with the persistent store?

Please use plain text.
Developer
Developer
CMY
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: PersistentStore Problem

Do you mean changing the KEY each time you call it? If that is the case, then you are creating a new object each time I think. This would not actually detect a deadlock as you are synchronizing on a different object each time.

Please use plain text.
Developer
tmountain
Posts: 90
Registered: ‎02-27-2009
My Device: Not Specified

Re: PersistentStore Problem

Nope, I mean just changing the key that refers to the persistent store solves the issue. I'm not changing it on each call because that would prevent the store from referring to the previously stored data. I have a constant for the key and changing the constant makes it work.

Please use plain text.