mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-27 04:33:00 +08:00
Use a thread pool when executing async plugin operations.
This commit is contained in:
parent
f53161d6f5
commit
18893bf6cd
@ -22,6 +22,8 @@ import java.io.IOException;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import org.apache.cordova.CordovaWebView;
|
import org.apache.cordova.CordovaWebView;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
@ -45,6 +47,7 @@ public class PluginManager {
|
|||||||
|
|
||||||
private final CordovaInterface ctx;
|
private final CordovaInterface ctx;
|
||||||
private final CordovaWebView app;
|
private final CordovaWebView app;
|
||||||
|
private final ExecutorService execThreadPool = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
// Flag to track first time through
|
// Flag to track first time through
|
||||||
private boolean firstRun;
|
private boolean firstRun;
|
||||||
@ -222,7 +225,7 @@ public class PluginManager {
|
|||||||
runAsync = async && !plugin.isSynch(action);
|
runAsync = async && !plugin.isSynch(action);
|
||||||
if (runAsync) {
|
if (runAsync) {
|
||||||
// Run this on a different thread so that this one can return back to JS
|
// Run this on a different thread so that this one can return back to JS
|
||||||
Thread thread = new Thread(new Runnable() {
|
execThreadPool.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
// Call execute on the plugin so that it can do it's thing
|
// Call execute on the plugin so that it can do it's thing
|
||||||
@ -234,7 +237,6 @@ public class PluginManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
thread.start();
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// Call execute on the plugin so that it can do it's thing
|
// Call execute on the plugin so that it can do it's thing
|
||||||
|
Loading…
Reference in New Issue
Block a user