realm-java
realm-java copied to clipboard
sharing objects between threads
in realm there is limitiation objects cannot be shared between diffrent thread, in order to do complex search + complex insert/remove/update query async, the only way is to be aware of the object structure and get some how the object id then copy the id to diffrent thread, and select this item on a diffrent thread, i think realm need to have some built in functility to copy objects from one thread to another asyncronycly, here is example of what i am doing now
abstract class ProductTransaction implements Realm.Transaction {
public final long productId;
ProductTransaction(Product product) {
this.productId = product.getProductId();
}
public abstract void execute(Realm realm, Product product);
@Override
public void execute(Realm realm) {
execute(realm, realm.where(Product.class)
.equalTo("productId", productId)
.findFirst());
}
}
i belive realm need to have something like this
abstract class ObjectTransactions<Model extends RealmObject> implements Realm.Transaction {
private Collection<Model> objects;
ObjectTransactions(Collection<Model> objects) {
this.objects = objects;
}
public abstract void execute(Realm realm, Collection<Model> objects);
@Override
public void execute(Realm realm) {
// some how copy the obejcts async
execute(realm, Realm.CopyObjectsFromAnotherThread(objects));
}
}
This probably ties into https://github.com/realm/realm-java/issues/4059
dup to #4059