All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.jrtps.udds.JRTPSThreadFactory Maven / Gradle / Ivy

There is a newer version: 1.5.1
Show newest version
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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy