- ac.add( clients.get( i ).getStub() ) ;
- clients.get( i ).setStatus( "running" ) ;
- ComputingClient cl = new ComputingClient( clients.get( i ) ) ;
- clients.get( i ).setComputingClient( cl ) ;
- computingClients.add( cl ) ;
- tmp.add( cl ) ;
- } else {
- System.err.println( "Problem while launching the VM on "
- + clients.get(i).getName() + "!" ) ;
+ synchronized( limitThread )
+ {
+ while( limitThread.getNb() >= maxThread )
+ {
+ try {
+ limitThread.wait() ;
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ limitThread.inc() ;
+ }
+
+ final int ind = i ;
+ new Thread( new Runnable(){
+
+ @Override
+ public void run()
+ {
+ int res = 1 ;
+ try {
+ res = clients.get( ind ).getStub().startVM( 0 ) ;
+ } catch( RemoteException e ) {
+ e.printStackTrace();
+ }
+
+ if( res == 0 )
+ {
+ ac.add( clients.get( ind ).getStub() ) ;
+ clients.get( ind ).setStatus( "running" ) ;
+ ComputingClient cl = new ComputingClient( clients.get( ind ) ) ;
+ clients.get( ind ).setComputingClient( cl ) ;
+ computingClients.add( cl ) ;
+ tmp.add( cl ) ;
+ } else {
+ System.err.println( "Problem while launching the VM on "
+ + clients.get(ind).getName() + "!" ) ;
+ }
+
+ synchronized( limitThread )
+ {
+ limitThread.dec() ;
+ limitThread.notifyAll() ;
+ }
+
+ synchronized( startingClients )
+ {
+ startingClients.dec() ;
+ startingClients.notifyAll() ;
+ }
+ }
+ }).start() ;