{"action":"closed","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/3558","repository_url":"https://api.github.com/repos/realm/realm-java","labels_url":"https://api.github.com/repos/realm/realm-java/issues/3558/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/3558/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/3558/events","html_url":"https://github.com/realm/realm-java/issues/3558","id":180952560,"number":3558,"title":"Realm is not always updated on another thread during the nearest runloop","user":{"login":"optisamit","id":10066131,"avatar_url":"https://avatars.githubusercontent.com/u/10066131?v=3","gravatar_id":"","url":"https://api.github.com/users/optisamit","html_url":"https://github.com/optisamit","followers_url":"https://api.github.com/users/optisamit/followers","following_url":"https://api.github.com/users/optisamit/following{/other_user}","gists_url":"https://api.github.com/users/optisamit/gists{/gist_id}","starred_url":"https://api.github.com/users/optisamit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/optisamit/subscriptions","organizations_url":"https://api.github.com/users/optisamit/orgs","repos_url":"https://api.github.com/users/optisamit/repos","events_url":"https://api.github.com/users/optisamit/events{/privacy}","received_events_url":"https://api.github.com/users/optisamit/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-java/labels/T:Duplicate","name":"T:Duplicate","color":"d4c5f9"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-10-04T17:16:42Z","updated_at":"2016-10-04T17:49:29Z","closed_at":"2016-10-04T17:49:29Z","body":"```java\r\npublic class MainActivity extends AppCompatActivity {\r\n\r\n    private int successCounts = 0;\r\n\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n        Realm.init(this);\r\n        test(1000);\r\n    }\r\n\r\n    public void test(final int count) {\r\n        final Realm realm = Realm.getDefaultInstance();\r\n        realm.executeTransaction(new Realm.Transaction() {\r\n            @Override\r\n            public void execute(Realm realm) {\r\n                realm.copyToRealmOrUpdate(new SimpleClass());\r\n            }\r\n        });\r\n\r\n        new AsyncTask<Void, Void, Void>() {\r\n            @Override\r\n            protected Void doInBackground(Void... params) {\r\n                final SimpleClass updatedObject = new SimpleClass();\r\n                updatedObject.bool = true;\r\n                final Realm realm = Realm.getDefaultInstance();\r\n                realm.executeTransaction(new Realm.Transaction() {\r\n                    @Override\r\n                    public void execute(Realm realm) {\r\n                        realm.copyToRealmOrUpdate(updatedObject);\r\n                    }\r\n                });\r\n                return null;\r\n            }\r\n\r\n            @Override\r\n            protected void onPostExecute(Void aVoid) {\r\n                if (Realm.getDefaultInstance().where(SimpleClass.class).findFirst().bool) {\r\n                    successCounts++;\r\n                }\r\n                if (count > 1) {\r\n                    runOnUiThread(new Runnable() {\r\n                        @Override\r\n                        public void run() {\r\n                            test(count - 1);\r\n                        }\r\n                    });\r\n                } else {\r\n                    Log.d(\"Bug\", \"Successful runs: \" + successCounts + \" out of 1000\");\r\n                }\r\n            }\r\n        }.execute();\r\n    }\r\n}\r\n\r\npublic class SimpleClass extends RealmObject {\r\n    @PrimaryKey\r\n    private String primaryKey = \"\";\r\n    public boolean bool;\r\n}\r\n```\r\n\r\n#### Expected result:\r\nD/Bug: Successful runs: 1000 out of 1000\r\n\r\n#### Actual result:\r\nD/Bug: Successful runs: 669 out of 1000\r\n\r\nIn general it's usually about 500-700\r\n\r\n#### Version of Realm and tooling\r\nRealm version(s): 2.0.0\r\n\r\nAndroid Studio version: 2.2\r\n\r\nWhich Android version and device: 4.2.2 on GT-9105"}}
{"actor":{"display_login":"cmelchior"}}