Skip to content

Commit a2a1fd0

Browse files
committed
Merge pull request #34 from ParsePlatform/grantland.ui_thread
Don't share locks across UI thread and long running processes
2 parents dd0a4a7 + 4d5096d commit a2a1fd0

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

Parse/src/main/java/com/parse/ParseCommandCache.java

+24-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.UnsupportedEncodingException;
2323
import java.util.Arrays;
2424
import java.util.HashMap;
25+
import java.util.concurrent.Callable;
2526
import java.util.logging.Level;
2627
import java.util.logging.Logger;
2728

@@ -93,13 +94,30 @@ public static int getPendingCount() {
9394
ConnectivityNotifier.ConnectivityListener listener = new ConnectivityNotifier.ConnectivityListener() {
9495
@Override
9596
public void networkConnectivityStatusChanged(Context context, Intent intent) {
96-
boolean connectionLost =
97+
final boolean connectionLost =
9798
intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
98-
if (connectionLost) {
99-
setConnected(false);
100-
} else {
101-
setConnected(ConnectivityNotifier.isConnected(context));
102-
}
99+
final boolean isConnected = ConnectivityNotifier.isConnected(context);
100+
101+
/*
102+
Hack to avoid blocking the UI thread with disk I/O
103+
104+
setConnected uses the same lock we use for synchronizing disk I/O, so there's a possibility
105+
that we can block the UI thread on disk I/O, so we're going to bump the lock usage to a
106+
different thread.
107+
108+
TODO(grantland): Convert to TaskQueue, similar to ParsePinningEventuallyQueue
109+
*/
110+
Task.call(new Callable<Void>() {
111+
@Override
112+
public Void call() throws Exception {
113+
if (connectionLost) {
114+
setConnected(false);
115+
} else {
116+
setConnected(isConnected);
117+
}
118+
return null;
119+
}
120+
}, ParseExecutors.io());
103121
}
104122
};
105123

0 commit comments

Comments
 (0)