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
darkberry
Posts: 178
Registered: ‎11-19-2008
My Device: Not Specified

Question about ObjectGroup

[ Edited ]

Hi.

I've some questions regarding ObjectGroup:

 

1.-Is the method ObjectGroup.expandGroup recursive? I mean, If some object contains, lets say, a collection, ungrouping the object implies ungrouping also the collection and the objects contained by it?

 

2.-Ungrouping an object wich is not grouped, has an impact in performance?

 

3.- Is it possible that  expandGroup may not behave recursively in case of handlers or persistent memory shortage?

 

Regarding question #3, I'm having an issue with severals 83XX. I've written an app under the assumption that point #1 is true. The app was thoroughly tested and it worked well for two months.

Now, following some weeks of coverage failures by the carrier, the deployed apps started to store a large ammount of data in persistence in order to be sent when the network is available, and some exceptions are appearing in the log.

The objects I have to persist contain BigVectors. They are grouped using the ObjectGroup.createGroupIgnoreTooBig method, and then retrieved using ObjectGroup.expandGroup on the container.

Despite being ungrouped, some BigVectors seems to be grouped, and an ObjectGroupReadOnlyException is thrown. This behaviour was never reported before, and it is occurring more frequently in recent days.

A workaround may be to perform ungrouping also in the BigVectors, but this seems pretty unnecessary to me.

 

Any hint?

Please use plain text.
Administrator
MSohm
Posts: 14,241
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Question about ObjectGroup

[ Edited ]

Grouped objects within a collection are also grouped.  This means that if you create an object group out of a Vector, the objects within the vector are also grouped in the same (single) group.

 

If you have a large amount of data within a single group you could be running into the case where you are trying to access an element before all objects have been ungrouped.  You may want to consider creating multiple object groups if you don't need to access the entire data set at one time.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
darkberry
Posts: 178
Registered: ‎11-19-2008
My Device: Not Specified

Re: Question about ObjectGroup

Thanks for your answer. So I must not suppose that calling expandGroup is a blocking operation.

Please use plain text.
Administrator
MSohm
Posts: 14,241
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Question about ObjectGroup

The object returned from ObjectGroup.expandGroup should be fully ungrouped already.  Can you post some sample code that triggers the exception?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
darkberry
Posts: 178
Registered: ‎11-19-2008
My Device: Not Specified

Re: Question about ObjectGroup

No, I can't. I've tried to reproduce the problem but couldn't.

The line that fails is a BigVector.elementAt(int). This is really strange since it is a read operation, but the log shows it clearly:

 

 

a Java Exception - ObjectGroupReadOnlyException - 12/3 13:36:44 
| No detail message 
| net_rim_cldc 
|  BigVector 
|  <private> 
|  0x17BE 
| net_rim_cldc 
|  BigVector 
|  elementAt 
|  0x11C5

 I think it has to be a multithreading issue.  However, every access to the objects are synchronized via RuntimeStore, grouping is performed on writings and ungrouping is performed when reading. Is it possible with two Threads under these conditions?

 

Please use plain text.
Developer
darkberry
Posts: 178
Registered: ‎11-19-2008
My Device: Not Specified

Re: Question about ObjectGroup

[ Edited ]

I think I have seen what is going on. The javadoc for expandGroup states:

"Return a new object which is a read-write clone of an object group"

 

Seems that the object is ungrouped and also the contained objects. The returned object is a new object, but perhaps this cloning is not recursive. If this is true, then it is possible that references to the BigVectors are shared among severals Threads. If another thread tries to retrieve the BigVector before being ungrouped, the exception is thrown.

 

 

Please use plain text.
Developer
darkberry
Posts: 178
Registered: ‎11-19-2008
My Device: Not Specified

Re: Question about ObjectGroup

I've performed some tests:

 

 

package main;

import java.util.Vector;
import net.rim.device.api.util.Persistable;

public class GroupableCollection implements Persistable {
private Vector sVector;

public GroupableCollection(){
sVector = new Vector();
}

public void setVector(Vector v){
sVector = v;
}

public Vector getVector(){
return sVector;
}
}

 

private static void testPersistence(){
final long ID = 0xb622af93ca138b3dL;
Vector v = new Vector();
for(int i = 0; i < 50000; i++){
v.addElement(new String("GC1 String #" + i+1));
}
GroupableCollection gc = new GroupableCollection();
gc.setVector(v);
PersistentObject persist = PersistentStore.getPersistentObject(ID);
ObjectGroup.createGroupIgnoreTooBig(gc);
persist.setContents(gc);
persist.commit();

Object o = ObjectGroup.expandGroup(persist.getContents());
System.out.println("Class of returned object: " + o.getClass().getName());
System.out.println("new object?: " + (o != gc));
System.out.println("Is in group?: " + ObjectGroup.isInGroup(o));
GroupableCollection gc2 = (GroupableCollection) o;
Vector v2 = gc2.getVector();
System.out.println("new collection?: " + (v2 != v));
for(int i = 0; i < v2.size(); i++){
String s = (String) v.elementAt(i);
}
}

 

 

You can run it by yourselves and see the results:

       Class of returned object: main.GroupableCollection
   new object?: false
   Is in group?: false
   new collection?: false

 

 

test findings:
-Ungrouping is performed recursively.
-Cloning is not performed at all (So what do you guys at RIM understand by "cloning"?).

 

Please use plain text.
Administrator
MSohm
Posts: 14,241
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Question about ObjectGroup

Since you are expanding the group you would be getting the same object back.  You are basically getting different references to the same object here, the first you cannot use for writing but the second you can.. 

 

Checking before you ungroup should yield different objects, but this may not occur 100% of the time due to internal optimizations.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.