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

com.github.panhongan.util.thread.ThreadManager Maven / Gradle / Ivy

There is a newer version: 0.1.8
Show newest version
package com.github.panhongan.util.thread;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class ThreadManager {
	
	private static final Logger logger = LoggerFactory.getLogger(ThreadManager.class);
	
	private List threads = new ArrayList();
	
	public void addThread(Thread t) {
		if (t != null) {
			threads.add(t);
			t.start();
		}
	}
	
	public void clear() {
		threads.clear();
	}
	
	public List getThreads() {
		return threads;
	}
	
	public void waitForCompletion() {
		for (Thread t : threads) {
			try {
				t.join();
				logger.info("thread finished : {}", t.getName());
			} catch (Exception e) {
				logger.warn(e.getMessage());
			}
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy