Skip to content

Commit

Permalink
Fixed threading issues in BaseJsonHttpResponseHandler and JsonHttpRes…
Browse files Browse the repository at this point in the history
…ponseHandler
  • Loading branch information
ypogribnyi committed Mar 28, 2014
1 parent eae48b8 commit 3ac8d50
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public BaseJsonHttpResponseHandler(String encoding) {
@Override
public final void onSuccess(final int statusCode, final Header[] headers, final String responseString) {
if (statusCode != HttpStatus.SC_NO_CONTENT) {
new Thread(new Runnable() {
Runnable parser = new Runnable() {
@Override
public void run() {
try {
Expand All @@ -95,7 +95,11 @@ public void run() {
});
}
}
}).start();
};
if (!getUseSynchronousMode())
new Thread(parser).start();
else // In synchronous mode everything should be run on one thread
parser.run();
} else {
onSuccess(statusCode, headers, null, null);
}
Expand All @@ -104,7 +108,7 @@ public void run() {
@Override
public final void onFailure(final int statusCode, final Header[] headers, final String responseString, final Throwable throwable) {
if (responseString != null) {
new Thread(new Runnable() {
Runnable parser = new Runnable() {
@Override
public void run() {
try {
Expand All @@ -125,7 +129,11 @@ public void run() {
});
}
}
}).start();
};
if (!getUseSynchronousMode())
new Thread(parser).start();
else // In synchronous mode everything should be run on one thread
parser.run();
} else {
onFailure(statusCode, headers, throwable, null, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void onSuccess(int statusCode, Header[] headers, String responseString) {
@Override
public final void onSuccess(final int statusCode, final Header[] headers, final byte[] responseBytes) {
if (statusCode != HttpStatus.SC_NO_CONTENT) {
new Thread(new Runnable() {
Runnable parser = new Runnable() {
@Override
public void run() {
try {
Expand Down Expand Up @@ -142,7 +142,11 @@ public void run() {
});
}
}
}).start();
};
if (!getUseSynchronousMode())
new Thread(parser).start();
else // In synchronous mode everything should be run on one thread
parser.run();
} else {
onSuccess(statusCode, headers, new JSONObject());
}
Expand All @@ -151,7 +155,7 @@ public void run() {
@Override
public final void onFailure(final int statusCode, final Header[] headers, final byte[] responseBytes, final Throwable throwable) {
if (responseBytes != null) {
new Thread(new Runnable() {
Runnable parser = new Runnable() {
@Override
public void run() {
try {
Expand Down Expand Up @@ -181,7 +185,11 @@ public void run() {

}
}
}).start();
};
if (!getUseSynchronousMode())
new Thread(parser).start();
else // In synchronous mode everything should be run on one thread
parser.run();
} else {
Log.v(LOG_TAG, "response body is null, calling onFailure(Throwable, JSONObject)");
onFailure(statusCode, headers, throwable, (JSONObject) null);
Expand Down

0 comments on commit 3ac8d50

Please sign in to comment.