1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
14 * @author Toni Kalajainen
\r
16 package org.simantics.utils.threads.test;
\r
18 import java.util.Random;
\r
20 import org.simantics.utils.threads.ThreadUtils;
\r
21 import org.simantics.utils.threads.WorkerThread;
\r
29 public static void main(String[] args) {
\r
30 final WorkerThread list[] = new WorkerThread[10];
\r
31 for (int i =0; i<list.length; i++)
\r
32 list[i] = new WorkerThread();
\r
34 for (WorkerThread t : list)
\r
37 final Random r = new Random();
\r
39 ExampleObject obj = new ExampleObject();
\r
41 ExampleListener l = new ExampleListener() {
\r
43 public void onMessage(ExampleObject sender, String msg) {
\r
46 } catch (InterruptedException e) {}
\r
47 System.out.println(Thread.currentThread()+": "+msg);
\r
48 ThreadUtils.syncExec(
\r
49 list[r.nextInt(list.length)],
\r
55 } catch (InterruptedException e) {}
\r
56 System.out.println("blaa");
\r
59 } catch (InterruptedException e) {}
\r
63 } catch (InterruptedException e) {}
\r
66 for (WorkerThread t : list)
\r
67 obj.addListener(t, l);
\r
69 obj.fireMessage("Test");
\r
70 System.out.println("jeps");
\r
72 for (WorkerThread t : list)
\r
73 t.stopDispatchingEvents(true);
\r