Skip to content
Snippets Groups Projects
Commit 39dbf2d0 authored by Daniel Schmidt's avatar Daniel Schmidt
Browse files

added demo code

parent 0b2acdff
No related branches found
No related tags found
1 merge request!1Initial gui, closes #5
......@@ -18,8 +18,28 @@ public class MainScene extends Control {
TextArea parallelCodeField;
private void setDemoText() {
currentCodeField.setText("# TODO: Put non parallel some code here");
parallelCodeField.setText("# TODO: put some parallel code here");
String current = "\n"
+ "public List<Output> processInputs(List<Input> inputs) throws InterruptedException, ExecutionException {\n"
+ "\t List<Output> outputs = new ArrayList<Output>();\n" + "\t for (Input input : inputs) {\n"
+ "\t\t Output result = 42; /* process your input here and compute the output */ \n"
+ "\t\t outputs.add(result);\n" + "\t } \n" + "\t return outputs; \n" + "}";
String parallel = "\n"
+ "public List<Output> processInputs(List<Input> inputs) throws InterruptedException, ExecutionException {\n"
+ "\t int threads = Runtime.getRuntime().availableProcessors();\n"
+ "\t ExecutorService service = Executors.newFixedThreadPool(threads);\n" + "\n"
+ "\t List<Future<Output>> futures = new ArrayList<Future<Output>>();\n"
+ "\t for (final Input input : inputs) {\n"
+ "\t\t Callable<Output> callable = new Callable<Output>() {\n"
+ "\t\t\t public Output call() throws Exception {\n" + "\t\t\t\t Output output = new Output();\n"
+ "\t\t\t\t // process your input here and compute the output\n" + "\t\t\t\t return output;\n"
+ "\t\t\t }\n" + "\t\t };\n" + "\t\t futures.add(service.submit(callable));\n" + "\t }\n"
+ "\t service.shutdown();\n" + "\n" + "\t List<Output> outputs = new ArrayList<Output>();\n"
+ "\t for (Future<Output> future : futures) {\n" + "\t\t outputs.add(future.get());\n" + "\t } \n"
+ "\t return outputs; \n" + "}";
currentCodeField.setText(current);
parallelCodeField.setText(parallel);
}
@FXML
......@@ -36,6 +56,7 @@ public class MainScene extends Control {
@FXML
private void handleStartAction(ActionEvent event) {
setDemoText();
progressBar.setProgress(0.9);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment