Académique Documents
Professionnel Documents
Culture Documents
Java Threads
// Anonymous Runnable
Runnable task1 = new Runnable(){
@Override
public void run(){
for( ; counter<20;counter++)
System.out.println("counting : "+counter);
}
};
Systèmes d’exploitation- 2AINFO 7 ENIT
// Passing a Runnable when creating a new thread
Thread thread2 = new Thread(new Runnable() {
@Override
public void run(){
for( ; counter<20;counter++)
System.out.println("counting : "+counter);
}
});
Thread thread1 = new Thread(task1);
thread1.start();
thread2.start();
}
}
Systèmes d’exploitation- 2AINFO 8 ENIT