Class ThreadManager

java.lang.Object
  |
  +--ThreadManager

class ThreadManager
extends java.lang.Object

Manager for the threads. Every threads is used for a connection for downloading a part of the ressource.


Field Summary
(package private) static int activeThreads
           
(package private) static int existingThreads
           
private  int maxSpareThreads
           
private  int maxThreads
           
private  int minSpareThreads
           
private  int minThreads
           
 
Constructor Summary
ThreadManager()
          Creates a new ThreadManager with default values as attributs. maxThreads = 50; minThreads = 5; maxSpareThreads = 5; minSpareThreads = 5; It doesn't create new Threads.
ThreadManager(int maxThreads, int minThreads, int maxSpareThreads, int minSpareThreads)
          It sets the bounds for the Threads, but it doesn't create new Threads.
 
Method Summary
 void initialize(java.lang.Class runnableClass)
          Method that creates minThreads Threads
 boolean mustCreateThread()
          This method return true if a new Thread must be created
 boolean mustDestroyThread()
          This method return true if an existing Thread must be destroyed
 void newThread(java.lang.Class runnableClass)
          Method that creates a new Thread, starts it and update attributs of the ThreadManager.
 void oneLessActiveThread()
          This method decrements the number of activated Threads Attention!!
 void oneLessExistingThread()
          This method decrements the number of existing Threads Attention!!
 void oneMoreActiveThread()
          This method increments the number of activated Threads Attention!!
 java.lang.String printStatus()
          This method returns a String describing the number of existing and activated Threads.
 void setAttributs(int maxThreads, int minThreads, int maxSpareThreads, int minSpareThreads)
          This method changes the bounds for the number of Threads
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

maxThreads

private int maxThreads

minThreads

private int minThreads

maxSpareThreads

private int maxSpareThreads

minSpareThreads

private int minSpareThreads

existingThreads

static int existingThreads

activeThreads

static int activeThreads
Constructor Detail

ThreadManager

public ThreadManager()
Creates a new ThreadManager with default values as attributs. maxThreads = 50; minThreads = 5; maxSpareThreads = 5; minSpareThreads = 5; It doesn't create new Threads. Threads must be created using the initialize() method.

ThreadManager

public ThreadManager(int maxThreads,
                     int minThreads,
                     int maxSpareThreads,
                     int minSpareThreads)
              throws IllegalValuesException
It sets the bounds for the Threads, but it doesn't create new Threads. Threads must be created using the initialize() method.
Parameters:
maxThreads - maximum number of existing Threads
minThreads - minimum number of existing Threads
maxSpareThreads - maximum number of disactivated Threads
minSpareThreads - minimum number of disactivated Threads
Method Detail

initialize

public void initialize(java.lang.Class runnableClass)
                throws java.lang.InstantiationException,
                       java.lang.IllegalAccessException
Method that creates minThreads Threads
Parameters:
c - Class extending Runnable, every new Thread manages a new object of this class

setAttributs

public void setAttributs(int maxThreads,
                         int minThreads,
                         int maxSpareThreads,
                         int minSpareThreads)
                  throws IllegalValuesException
This method changes the bounds for the number of Threads
Parameters:
maxThreads - new maximum number of existing Threads
minThreads - new minimum number of existing Threads
maxSpareThreads - new maximum number of disactivated Threads
minSpareThreads - new minimum number of disactivated Threads
Throws:
IllegalValuesException -  

printStatus

public java.lang.String printStatus()
This method returns a String describing the number of existing and activated Threads.
Returns:
a String with number and status of threads

newThread

public void newThread(java.lang.Class runnableClass)
               throws java.lang.InstantiationException,
                      java.lang.IllegalAccessException
Method that creates a new Thread, starts it and update attributs of the ThreadManager.
Parameters:
objectRunnable - An object instance of Runnable, managed by a new Thread
Throws:
InstantiationException, - IllegalAccessException

oneMoreActiveThread

public void oneMoreActiveThread()
This method increments the number of activated Threads Attention!! It doesn't activate a Thread.

oneLessActiveThread

public void oneLessActiveThread()
This method decrements the number of activated Threads Attention!! It doesn't deactivate a Thread.

oneLessExistingThread

public void oneLessExistingThread()
This method decrements the number of existing Threads Attention!! It doesn't destroy a Thread.

mustCreateThread

public boolean mustCreateThread()
This method return true if a new Thread must be created

mustDestroyThread

public boolean mustDestroyThread()
This method return true if an existing Thread must be destroyed