From 18893bf6cd32e05892c262679eff2adb0868e772 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Tue, 11 Sep 2012 14:36:25 -0400 Subject: [PATCH] Use a thread pool when executing async plugin operations. --- framework/src/org/apache/cordova/api/PluginManager.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/framework/src/org/apache/cordova/api/PluginManager.java b/framework/src/org/apache/cordova/api/PluginManager.java index 99b8aeb8..3230b57f 100755 --- a/framework/src/org/apache/cordova/api/PluginManager.java +++ b/framework/src/org/apache/cordova/api/PluginManager.java @@ -22,6 +22,8 @@ import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import org.apache.cordova.CordovaWebView; import org.json.JSONArray; @@ -45,6 +47,7 @@ public class PluginManager { private final CordovaInterface ctx; private final CordovaWebView app; + private final ExecutorService execThreadPool = Executors.newCachedThreadPool(); // Flag to track first time through private boolean firstRun; @@ -222,7 +225,7 @@ public class PluginManager { runAsync = async && !plugin.isSynch(action); if (runAsync) { // 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() { try { // Call execute on the plugin so that it can do it's thing @@ -234,7 +237,6 @@ public class PluginManager { } } }); - thread.start(); return; } else { // Call execute on the plugin so that it can do it's thing