]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/test/Test.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.utils.thread / src / org / simantics / utils / threads / test / Test.java
diff --git a/bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/test/Test.java b/bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/test/Test.java
new file mode 100644 (file)
index 0000000..900b651
--- /dev/null
@@ -0,0 +1,76 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+/*\r
+ *\r
+ * @author Toni Kalajainen\r
+ */\r
+package org.simantics.utils.threads.test;\r
+\r
+import java.util.Random;\r
+\r
+import org.simantics.utils.threads.ThreadUtils;\r
+import org.simantics.utils.threads.WorkerThread;\r
+\r
+\r
+public class Test {\r
+\r
+       /**\r
+        * @param args\r
+        */\r
+       public static void main(String[] args) {\r
+               final WorkerThread list[] = new WorkerThread[10];\r
+               for (int i =0; i<list.length; i++)\r
+                       list[i] = new WorkerThread();\r
+               \r
+               for (WorkerThread t : list)\r
+                       t.start();\r
+               \r
+               final Random r = new Random();\r
+               \r
+               ExampleObject obj = new ExampleObject();\r
+               \r
+               ExampleListener l = new ExampleListener() {\r
+                       @Override\r
+                       public void onMessage(ExampleObject sender, String msg) {\r
+                               try {\r
+                                       Thread.sleep(1000);\r
+                               } catch (InterruptedException e) {}\r
+                               System.out.println(Thread.currentThread()+": "+msg);\r
+                               ThreadUtils.syncExec(\r
+                                               list[r.nextInt(list.length)],\r
+                                               new Runnable() {\r
+                                                       @Override\r
+                                                       public void run() {\r
+                                                               try {\r
+                                                                       Thread.sleep(1000);\r
+                                                               } catch (InterruptedException e) {}\r
+                                                               System.out.println("blaa");\r
+                                                               try {\r
+                                                                       Thread.sleep(1000);\r
+                                                               } catch (InterruptedException e) {}\r
+                                                       }});\r
+                               try {\r
+                                       Thread.sleep(1000);\r
+                               } catch (InterruptedException e) {}\r
+                       }};\r
+               \r
+               for (WorkerThread t : list)                                             \r
+                       obj.addListener(t, l);\r
+               \r
+               obj.fireMessage("Test");\r
+               System.out.println("jeps");\r
+\r
+               for (WorkerThread t : list)\r
+                       t.stopDispatchingEvents(true);\r
+       }\r
+\r
+}\r