Clover coverage report - CRISPY - 1.1.1
Coverage timestamp: Mi Nov 15 2006 13:09:46 CET
file stats: LOC: 70   Methods: 5
NCLOC: 39   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ThreadController.java 100% 100% 100% 100%
coverage
 1    package net.sf.crispy.concurrent;
 2   
 3    import java.util.ArrayList;
 4    import java.util.List;
 5   
 6    import net.sf.crispy.InvocationException;
 7   
 8    /**
 9    * This class create and controlled all Threads.
 10    *
 11    * @author Linke
 12    * @since Verion 1.0
 13    *
 14    */
 15    public class ThreadController {
 16   
 17    private int maxThreads = 0;
 18    private int threadCounter = 0;
 19    private final List pool = new ArrayList();
 20    private ThreadWorker singleton = new ThreadWorker(this);
 21   
 22   
 23  128 public void setMaxThreads(int pvMaxThreads) {
 24  128 maxThreads = pvMaxThreads;
 25    }
 26  623 public int getMaxThreads() {
 27  623 return maxThreads;
 28    }
 29   
 30    /**
 31    * Get a new <code>ThreadWorker (Thread)</code> or from pool.
 32    *
 33    * @return ThreadWorker - Thread
 34    */
 35  319 public synchronized ThreadWorker getThreadWorker() {
 36  319 if (getMaxThreads() > 0 && threadCounter == getMaxThreads()) {
 37  3 throw new InvocationException("Maximum number of concurrent Threads exceeded: " + getMaxThreads() + ". A asynchrone invocation is not possible.");
 38    }
 39   
 40  316 ++threadCounter;
 41  316 if (maxThreads == 0) {
 42  20 return singleton;
 43    }
 44  296 if (pool.size() == 0) {
 45  220 return new ThreadWorker(this);
 46    } else {
 47  76 return (ThreadWorker) pool.remove(pool.size() - 1);
 48    }
 49    }
 50   
 51    /**
 52    * Release <code>ThreadWorker (Thread)</code>
 53    * @param pvThreadWorker the Thread
 54    */
 55  319 public synchronized void releasThreadWorker(ThreadWorker pvThreadWorker) {
 56  319 --threadCounter;
 57  319 if ((pvThreadWorker != singleton) && (pool.size() < maxThreads)) {
 58  262 pool.add(pvThreadWorker);
 59    }
 60    }
 61   
 62   
 63    /**
 64    * Returns the number of currently running Threads.
 65    * @return Current number of Threads.
 66    */
 67  14 public synchronized int getCurrentRequests() {
 68  14 return threadCounter;
 69    }
 70    }