Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Pontesegger2015-10-07 09:19:16 +0000
committerChristian Pontesegger2015-10-07 09:19:16 +0000
commit1f7278e9e811b11f7aaae8b511af5bf4eeca23bb (patch)
tree71a2c108a15c3de5f21e735624f5d2aac4df5bbd /JavaScript Beginner Tutorial
parent3de8fa6ff2211746792f86c6d266873f747088a9 (diff)
downloadorg.eclipse.ease.scripts-1f7278e9e811b11f7aaae8b511af5bf4eeca23bb.tar.gz
org.eclipse.ease.scripts-1f7278e9e811b11f7aaae8b511af5bf4eeca23bb.tar.xz
org.eclipse.ease.scripts-1f7278e9e811b11f7aaae8b511af5bf4eeca23bb.zip
added threading tutorials
Diffstat (limited to 'JavaScript Beginner Tutorial')
-rw-r--r--JavaScript Beginner Tutorial/03 Threading/Master.js30
-rw-r--r--JavaScript Beginner Tutorial/03 Threading/Thread A.js26
-rw-r--r--JavaScript Beginner Tutorial/03 Threading/Thread B.js29
3 files changed, 85 insertions, 0 deletions
diff --git a/JavaScript Beginner Tutorial/03 Threading/Master.js b/JavaScript Beginner Tutorial/03 Threading/Master.js
new file mode 100644
index 0000000..a86a4a4
--- /dev/null
+++ b/JavaScript Beginner Tutorial/03 Threading/Master.js
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Christian Pontesegger and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian Pontesegger - initial API and implementation
+ *******************************************************************************/
+
+loadModule('/System/Scripting');
+
+print("Master start")
+print("==============================================");
+
+// create a shared object to be used in spawned threads
+file = new java.io.File("/root");
+setSharedObject("file", file);
+
+// spawn 2 engines
+engineA = fork("Thread A.js");
+engineB = fork("Thread B.js", "pass, some, delimited, script arguments");
+
+// wait for engines to be terminated
+join(engineA);
+join(engineB);
+
+print("==============================================");
+print("Master done") \ No newline at end of file
diff --git a/JavaScript Beginner Tutorial/03 Threading/Thread A.js b/JavaScript Beginner Tutorial/03 Threading/Thread A.js
new file mode 100644
index 0000000..fc1c0aa
--- /dev/null
+++ b/JavaScript Beginner Tutorial/03 Threading/Thread A.js
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Christian Pontesegger and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian Pontesegger - initial API and implementation
+ *******************************************************************************/
+
+function sleep(time) {
+ start = java.lang.System.currentTimeMillis();
+ while (start + time > java.lang.System.currentTimeMillis())
+ ;
+}
+
+loadModule('/System/Scripting');
+
+file = getSharedObject("file");
+print("Thread A: " + file);
+
+for (var i = 1; i< 15; i++) {
+ print("Thread A, " + i);
+ sleep(6);
+} \ No newline at end of file
diff --git a/JavaScript Beginner Tutorial/03 Threading/Thread B.js b/JavaScript Beginner Tutorial/03 Threading/Thread B.js
new file mode 100644
index 0000000..9470611
--- /dev/null
+++ b/JavaScript Beginner Tutorial/03 Threading/Thread B.js
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Christian Pontesegger and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian Pontesegger - initial API and implementation
+ *******************************************************************************/
+
+function sleep(time) {
+ start = java.lang.System.currentTimeMillis();
+ while (start + time > java.lang.System.currentTimeMillis())
+ ;
+}
+
+for each (arg in argv)
+ print("Argument: " + arg);
+
+loadModule('/System/Scripting');
+
+file = getSharedObject("file");
+print("Thread B: " + file);
+
+for (var i = 1; i< 10; i++) {
+ print("Thread B, " + i);
+ sleep(10);
+} \ No newline at end of file

Back to the top