Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ThreadEsempio extends Thread {
- String nome;
- public ThreadEsempio(String nome) {
- this.nome=nome;
- }
- @Override
- public void run() {
- for (int i = 0; i < 10; i++) {
- System.out.println(i + " " + nome);
- try {
- sleep((int)(Math.random() * 1000));
- } catch (InterruptedException e) {}
- }
- System.out.println(nome + " terminato");
- }
- public static void main(String[] args) throws InterruptedException {
- ThreadEsempio t = new ThreadEsempio("Pippo");
- t.start();
- ThreadEsempio t1= new ThreadEsempio("Pluto");
- t1.start();
- t.join();t1.join();
- System.out.println("Programma terminato");
- }
- }
Add Comment
Please, Sign In to add comment