Note that there are some explanatory texts on larger screens.

plurals
  1. POTask speed difference between main function and ExecutorService
    text
    copied!<p>So, I have an executor service that creates 12 threads with 250ms of sleep in between each, this amount of time is usually sufficient for most of my threads to complete, however I have one thread created that is especially process intensive and usually takes about 7-10 seconds to parse.</p> <p>If I let that run in my main thread, it completes without error, however if I feed it into my executor service, it doesn't.</p> <p>Here's my code:</p> <pre><code>public static void main(String args[]){ ExecutorService threadPool = Executors.newFixedThreadPool(12); ... Thread.sleep(250); OPA.OpaHandler OpaSH = new OPA.OpaHandler(); threadPool.submit(new ThreadHandler(OpaSH, 7)); Thread.sleep(250); ... ThreadHandler.java .... public void run(){ double startTime; double endTime; switch(this.threadNum){ .... case 7:{ startTime = System.nanoTime(); OpaSH.run(); endTime = System.nanoTime(); endTime = endTime - startTime; System.out.println("Thread 7 (OPA) took:" + (endTime/1000000000) + " seconds. to run"); break; } </code></pre> <p>The only notable part of OpaSH.run();</p> <pre><code> supply = new double[9]; // Create an XML reader DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse(in); //Parse the Xml. XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expr = xpath.compile("//Stuff[1]/text()"); result = (String) expr.evaluate(doc, XPathConstants.STRING); supply[0] = Double.parseDouble(result); expr = xpath.compile("//Stuff[2]/text()"); result = (String) expr.evaluate(doc, XPathConstants.STRING); supply[1] = Double.parseDouble(result); .... </code></pre> <p>There is a total of 12 threads that run, the time to complete each is between 0.07s and 0.8s to compute. There are two that take significantly longer (about 9s and OPA which can be anywhere from 1s to 55s)</p> <p>Why is this happening and how can I fix it?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload