1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
14 * @author Toni Kalajainen
16 package org.simantics.utils.threads.test;
18 import java.util.Random;
20 import org.simantics.utils.threads.ThreadUtils;
21 import org.simantics.utils.threads.WorkerThread;
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();
34 for (WorkerThread t : list)
37 final Random r = new Random();
39 ExampleObject obj = new ExampleObject();
41 ExampleListener l = new ExampleListener() {
43 public void onMessage(ExampleObject sender, String msg) {
46 } catch (InterruptedException e) {}
47 System.out.println(Thread.currentThread()+": "+msg);
49 list[r.nextInt(list.length)],
55 } catch (InterruptedException e) {}
56 System.out.println("blaa");
59 } catch (InterruptedException e) {}
63 } catch (InterruptedException e) {}
66 for (WorkerThread t : list)
67 obj.addListener(t, l);
69 obj.fireMessage("Test");
70 System.out.println("jeps");
72 for (WorkerThread t : list)
73 t.stopDispatchingEvents(true);