]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/test/Test.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils.thread / src / org / simantics / utils / threads / test / Test.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 /*
13  *
14  * @author Toni Kalajainen
15  */
16 package org.simantics.utils.threads.test;
17
18 import java.util.Random;
19
20 import org.simantics.utils.threads.ThreadUtils;
21 import org.simantics.utils.threads.WorkerThread;
22
23
24 public class Test {
25
26         /**
27          * @param args
28          */
29         public static void main(String[] args) {
30                 final WorkerThread list[] = new WorkerThread[10];
31                 for (int i =0; i<list.length; i++)
32                         list[i] = new WorkerThread();
33                 
34                 for (WorkerThread t : list)
35                         t.start();
36                 
37                 final Random r = new Random();
38                 
39                 ExampleObject obj = new ExampleObject();
40                 
41                 ExampleListener l = new ExampleListener() {
42                         @Override
43                         public void onMessage(ExampleObject sender, String msg) {
44                                 try {
45                                         Thread.sleep(1000);
46                                 } catch (InterruptedException e) {}
47                                 System.out.println(Thread.currentThread()+": "+msg);
48                                 ThreadUtils.syncExec(
49                                                 list[r.nextInt(list.length)],
50                                                 new Runnable() {
51                                                         @Override
52                                                         public void run() {
53                                                                 try {
54                                                                         Thread.sleep(1000);
55                                                                 } catch (InterruptedException e) {}
56                                                                 System.out.println("blaa");
57                                                                 try {
58                                                                         Thread.sleep(1000);
59                                                                 } catch (InterruptedException e) {}
60                                                         }});
61                                 try {
62                                         Thread.sleep(1000);
63                                 } catch (InterruptedException e) {}
64                         }};
65                 
66                 for (WorkerThread t : list)                                             
67                         obj.addListener(t, l);
68                 
69                 obj.fireMessage("Test");
70                 System.out.println("jeps");
71
72                 for (WorkerThread t : list)
73                         t.stopDispatchingEvents(true);
74         }
75
76 }