Code example for CopyOnWriteArraySet

0
/** 
 * User: Anton Koscejev 
 * Created: 11.12.11 22:21 
 */ 
public class Example8 { 
	static Set<Thread> uniqueThreads = new CopyOnWriteArraySet<>();
 
	public static void main(String[] args) throws InterruptedException {
		uniqueThreads.add(Thread.currentThread());
		ExecutorService executor = Executors.newFixedThreadPool(10);
		for (int i = 0; i < 1000; i++) {
			executor.submit(new MyWorker());
		} 
		/* 
		executor.shutdown(); 
		while (!executor.awaitTermination(1000, TimeUnit.MILLISECONDS)) { 
			Thread.sleep(1); 
		} 
		*/ 
		System.out.println("Unique threads: " + uniqueThreads.size());
	}