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
Posts: 78
Registered: ‎12-22-2010
My Device: Not Specified

Does runtimestore access need synchronization, really?

I've seen various examples where the runtimestore is synchronized, it includes official blackberry knowledgebase:

 

 

My question is, according to the Javadoc, the Runtimestore is an object shared among all applications, meaning that if an application deadlocks inside a synchronzied(runtimestore) block, it potentially will deadlock all running applications that's also trying to synchronize on the RuntimeStore.  It includes a third-party application suite preloaded on many blackberries, which I won't name here.
In this light, is synchronized(runtimestore) necessary?  My common sense tells me no...

 

Developer
Posts: 16,516
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Does runtimestore access need synchronization, really?

my guess would also be no, unless you check something and proceed with the result (for example check for existance and replace, then). but i don't know an official answer about that. usually the code within the sync should be quite short and not producing any locks.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
Posts: 78
Registered: ‎12-22-2010
My Device: Not Specified

Re: Does runtimestore access need synchronization, really?

Usually the code within the sync should be quite short, yes.

 

However, if let's say I'm talking about a malicious application that specifically tries to lock other applications...

Developer
Posts: 16,516
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Does runtimestore access need synchronization, really?

i dunno, the code sample you linked is quite ancient. OS 3.6? In any case, i think your question could only be answered by somebody who knows details about the JVM implementation. how about trying it and posting the result? :smileyhappy:
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
Posts: 78
Registered: ‎12-22-2010
My Device: Not Specified

Re: Does runtimestore access need synchronization, really?

I did try writing such app and tested it on my device, and yes it killed several other apps this way, that's why I'm asking... :smileyhappy:

New Developer
Posts: 78
Registered: ‎12-22-2010
My Device: Not Specified

Re: Does runtimestore access need synchronization, really?

[ Edited ]

Anyone?  Mark S?  I still believe synchronizing on the RuntimeStore makes your app vulnerable to being deadlocked by another app, but since it is a practice documented in the knowledge base, need someone to confirm whether I can read to and write from the RuntimeStore without synchronization and without corrupting it.

 

My tests cannot confirm anything because there's always the chance I'm just being lucky when it comes to race conditions.

 

Thanks.

New Developer
Posts: 78
Registered: ‎12-22-2010
My Device: Not Specified

Re: Does runtimestore access need synchronization, really?

Sorry for bumping my post.  Is there anyone who knows how the RuntimeStore should be used can let us know whether synchronization is required?

 

Can I trust the example code in the knowledge base, where access need synchronization?

 

And if I must synchronize on the RuntimeStore, how can applications make sure they won't be deadlocked by another badly-written application?

 

Thanks!

 

Developer
Posts: 16,516
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Does runtimestore access need synchronization, really?

in the past years i have never encountered an issue by not synchronizing the runtimestore.

I think your concerns are valid, albeit the scenario is not very likely.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
Posts: 78
Registered: ‎12-22-2010
My Device: Not Specified

Re: Does runtimestore access need synchronization, really?

I have already stopped syncing.  A lot of apps still seems to be doing this, an example is the Docs to Go Suite - they locked up when I ran my badly written application.

 

The much more concerning aspect of my question is whether I can rely anymore on codes posted on the developer knowledge base as the final authority on how things should be written in the absence of examples in the Javadoc.

 

Developer
Posts: 16,516
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Does runtimestore access need synchronization, really?

Most developers working for RIM are experienced and write good code, but not all code examples should be taken as the ultimate solution (good is not always the same as the best).

I have improved some RIM samples myself, some do not adhere to naming conventions or are badly documented...

Some samples are also very old, and there may be better ways to achieve things then with the 3.6 API.

 

I trust RIM samples to be working correctly, but all software may contain bugs, even after being tested.

And I take them as samples, not as a rule about how to write my own code.

 

I guess you can go ahead and PM Mark Sohm or Garett Beukeboom with your specific question about the synchronized, but i doubt that there are any special secrets to be gained there.

Synchronization makes you safe against some problems while making you vulnerable to others, if there was no tradeoff all code would use it.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter