net.sf.jrtps.udds.JRTPSThreadFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jrtps Show documentation
Show all versions of jrtps Show documentation
jRTPS - An implementation of RTPS protocol by OMG
package net.sf.jrtps.udds;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ThreadFactory;
/**
* A ThreadFactory, that sets names of the threads.
*
* @author mcr70
*/
class JRTPSThreadFactory implements ThreadFactory {
private final String prefix;
private int count = 0;
private List threads = new LinkedList<>();
public JRTPSThreadFactory(int domainId) {
prefix = "jrtps-d" + domainId + "-t";
}
@Override
public synchronized Thread newThread(Runnable r) {
Thread thread = new Thread(r, prefix + count++);
thread.setDaemon(true);
return thread;
}
/**
* Called after participant close
*/
synchronized void stopThreads() {
for (Thread t : threads) {
t.stop();
}
threads.clear();
}
}