public class ThreadName extends Thread { private Thread mon_thread; public ThreadName() { // Noter le thread crée par notre classe mon_thread = Thread.currentThread(); } public void run() { for ( int i = 0; i < 10; i++ ) { // A chaque exécution, afficher le nom du thread afficherNom(); // Modifier le nom du thread en cours d'exécution if(i>0) this.setName("Thread sakoba"); } } // Trouver et afficher le nom du Thread public void afficherNom() { Thread t = Thread.currentThread(); String nom= t.getName(); System.out.println ("Thread "+nom+ " est en cours d'exécution"); } public static void main(String[] argv) { Thread thr = new ThreadName(); thr.start(); } } |
Cet article Java: Trouver et modifier le nom d’un thread est apparu en premier sur .