Skip to content

Commit

Permalink
Merge pull request #34 from ParsePlatform/grantland.ui_thread
Browse files Browse the repository at this point in the history
Don't share locks across UI thread and long running processes
  • Loading branch information
grantland committed Sep 4, 2015
2 parents dd0a4a7 + 4d5096d commit a2a1fd0
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions Parse/src/main/java/com/parse/ParseCommandCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -93,13 +94,30 @@ public static int getPendingCount() {
ConnectivityNotifier.ConnectivityListener listener = new ConnectivityNotifier.ConnectivityListener() {
@Override
public void networkConnectivityStatusChanged(Context context, Intent intent) {
boolean connectionLost =
final boolean connectionLost =
intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
if (connectionLost) {
setConnected(false);
} else {
setConnected(ConnectivityNotifier.isConnected(context));
}
final boolean isConnected = ConnectivityNotifier.isConnected(context);

/*
Hack to avoid blocking the UI thread with disk I/O
setConnected uses the same lock we use for synchronizing disk I/O, so there's a possibility
that we can block the UI thread on disk I/O, so we're going to bump the lock usage to a
different thread.
TODO(grantland): Convert to TaskQueue, similar to ParsePinningEventuallyQueue
*/
Task.call(new Callable<Void>() {
@Override
public Void call() throws Exception {
if (connectionLost) {
setConnected(false);
} else {
setConnected(isConnected);
}
return null;
}
}, ParseExecutors.io());
}
};

Expand Down

0 comments on commit a2a1fd0

Please sign in to comment.