public void stop() { if (isRunning) { proc.destroy(); try { proc.waitFor(); } catch (InterruptedException e) { log.error(e.getMessage()); } isRunning = false; Thread.currentThread().interrupt(); } }
public void run() { build(); isRunning = true; // Start the Data Process for (int i = 0; i < dataProcesses.size(); i++) { new Thread(dataProcesses.get(i)).start(); } // Start the C++ Operation String[] compile = null; String run = ""; if (OS == 0) { String[] tcompile = { "sh", contextPath + "proc/Debug/compile.sh", queryID, "EmageOperators_" + queryID }; compile = tcompile; run = contextPath + "proc/Debug/EmageOperators_" + queryID; } else if (OS == 1) { String[] tcompile = { "\"" + contextPath + "proc\\Debug\\compile.bat\"", queryID, "EmageOperators_" + queryID }; // changed due to new proj structure compile = tcompile; run = "\"" + contextPath + "proc\\Debug\\EmageOperators_" + queryID + ".exe\""; // changed due to new proj structure } try { if (compile != null && run != "") { // Compile the query proc = Runtime.getRuntime().exec(compile); InputStream inputStream = proc.getInputStream(); InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String line; while ((line = bufferedReader.readLine()) != null) { log.info(line); } proc.destroy(); proc.waitFor(); log.info("Compiled!"); // Run the query proc = Runtime.getRuntime().exec(run); inputStream = proc.getInputStream(); inputStreamReader = new InputStreamReader(inputStream); bufferedReader = new BufferedReader(inputStreamReader); while (isRunning && (line = bufferedReader.readLine()) != null) { log.info(line); } log.info("Run!"); } } catch (IOException e) { log.error(e.getMessage()); } catch (InterruptedException e) { log.error(e.getMessage()); } catch (Exception e) { log.error(e.getMessage()); stop(); } }