Salve,

Non capisco la successione dell'output del seguente esempio (che ho semplificato per brevità):

Codice PHP:
public class ThreadTester {
   public static 
void mainString args[] )
   {
      
PrintThread thread1thread2;

      
thread1 = new PrintThread"thread1" );
      
thread2 = new PrintThread"thread2" );
     
      
System.err.println"\nStarting threads" );

      
thread1.start();
      
thread2.start();
     
      
System.err.println"Threads started\n" );
   }
}

class 
PrintThread extends Thread {
   private 
int sleepTime;

   public 
PrintThreadString name )
   {
      
supername );

      
sleepTime 2;

      
System.err.println"Name: " getName() +
                          
";  sleep: " sleepTime );
   }

   public 
void run()
   {
      try {
         
System.err.printlngetName() + " going to sleep" );
         
Thread.sleepsleepTime );
      }
      catch ( 
InterruptedException exception ) {
         
System.err.printlnexception.toString() );
      }

      
System.err.printlngetName() + " done sleeping" );
   }

Ecco l'output:
Name: thread1; sleep: 2
Name: thread2; sleep: 2

Starting threads
Threads started

thread1 going to sleep
thread2 going to sleep
thread1 done sleeping
thread2 done sleeping
Perchè la stringa Threads started non sta alla fine?

Grazie dell'attenzione.
Matteo