View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.processor;
5   import java.util.Collections;
6   import java.util.LinkedList;
7   import java.util.List;
8   import java.util.concurrent.ThreadFactory;
9   import java.util.concurrent.atomic.AtomicInteger;
10  
11  import net.sourceforge.pmd.RuleContext;
12  import net.sourceforge.pmd.RuleSetFactory;
13  
14  public class PmdThreadFactory implements ThreadFactory {
15  	
16  		private final RuleSetFactory ruleSetFactory;
17  		private final RuleContext ctx;
18  		private final AtomicInteger counter = new AtomicInteger();
19  
20  		public PmdThreadFactory(RuleSetFactory ruleSetFactory, RuleContext ctx) {
21  			this.ruleSetFactory = ruleSetFactory;
22  			this.ctx = ctx;
23  		}
24  
25  		public Thread newThread(Runnable r) {
26  			Thread t = PmdRunnable.createThread(counter.incrementAndGet(), r,
27  					ruleSetFactory, ctx);
28  			threadList.add(t);
29  			return t;
30  		}
31  
32  		public List<Runnable> threadList = Collections
33  				.synchronizedList(new LinkedList<Runnable>());
34  
35  }