public boolean processPhase2(BundlePhase2 bundle) { Map<String, XmlvmResource> mappedResources = new HashMap<String, XmlvmResource>(); for (XmlvmResource resource : bundle.getResources()) { mappedResources.put(resource.getFullName(), resource); } long startTime = System.currentTimeMillis(); XmlvmResource[] allResources = mappedResources.values().toArray(new XmlvmResource[0]); int threadCount = Runtime.getRuntime().availableProcessors(); int itemsPerThread = (int) Math.ceil(allResources.length / (float) threadCount); Log.debug(TAG, "Threads: " + threadCount); Log.debug(TAG, "Items per thread: " + itemsPerThread); JavaScriptTranslationThread[] threads = new JavaScriptTranslationThread[threadCount]; // Divide work and start the threads. for (int i = 0; i < threadCount; ++i) { int start = i * itemsPerThread; int end = Math.min(start + itemsPerThread - 1, allResources.length - 1); threads[i] = new JavaScriptTranslationThread(allResources, start, end, bundle); threads[i].start(); } // Wait for threads to finish. for (int i = 0; i < threadCount; ++i) { try { threads[i].join(); } catch (InterruptedException e) { e.printStackTrace(); return false; } } long endTime = System.currentTimeMillis(); Log.debug(TAG, "JS Processing took: " + (endTime - startTime) + " ms."); return true; }