6Fermer8
Pen^2Le 14/12/2009 à 10:44
L'hiver dernier il faisait froid au bureau, donc j'avais implémenté ça :

import java.io.IOException ;


/**
 * @author Pen^2
 */
public class Heater
{
   public static void main( String[] args )
   {
      for ( int i= nbCores * nbProcs ; i > 0 ; --i ) {
         final int heaterIndex= i ;
         new Thread() {
            @Override
            public void run()
            {
               setPriority(MIN_PRIORITY) ;
               while ( !stopHeaters )
                  yield() ;
               
               System.out.println("Heater "+heaterIndex+" stopped!") ;
            }
         }.start() ;
         System.out.println("Heater "+heaterIndex+" started ...") ;
      }
      try {
         System.in.read() ;
      }
      catch ( IOException ioe ) {
      }
      finally {
         stopHeaters= true ;
      }
   }

   
   
   private static volatile boolean stopHeaters ;
   
   
   private static final int nbCores= 4 ;
   private static final int nbProcs= 1 ;
}

Si ça peut servir à quelqu'un tripo