Generation

generate functionSat, 06 May 2023

Identifique la realizacion de un modo alternado de los procesos ("PROC1" , "PROC1"y "PROC2" de forma indefinida.

public static void main(String[] args) { Thread t1 = new Thread(){ @Override public void run() { int i=0; while (true){ System.out.println(i+" PROC1 "); i++; try { Thread.sleep(1000); } catch (InterruptedException ex) { } } } }; Thread t2 = new Thread(){ @Override public void run() { int i=0; while (true){ System.out.println(i+" PROC2 "); i++; try { Thread.sleep(1000); } catch (InterruptedException ex) { } } } }; t1.start(); t2.start(); }

Questions about programming?Chat with your personal AI assistant