blob: ba82b5eb3146f09df7aada25c097e6b06f7c2f02 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* 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:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.ote.core.framework.thread;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ThreadFactory;
/**
* @author Roberto E. Escobar
*/
public class OteThreadFactory implements ThreadFactory {
private final List<WeakReference<OteThread>> threads;
private final String threadName;
protected OteThreadFactory(String threadName) {
this.threadName = threadName;
this.threads = new CopyOnWriteArrayList<>();
}
@Override
public Thread newThread(Runnable runnable) {
OteThread thread = new OteThread(runnable, threadName + ":" + threads.size());
this.threads.add(new WeakReference<OteThread>(thread));
return thread;
}
public List<OteThread> getThreads() {
List<OteThread> toReturn = new ArrayList<>();
for (WeakReference<OteThread> weak : threads) {
OteThread thread = weak.get();
if (thread != null) {
toReturn.add(thread);
}
}
return toReturn;
}
}
|