How to make the threads (the sequence is not important), every second deduced the inscription? It is important for synchronization to work, for one thread to go into the body of the method, while others wait, execute, then another random thread also go to execute, and all others wait again ... just like this
public class qq { public static void main ( String [] args ) throws UnknownHostException, InterruptedException { for (int i = 0; i < 5; i++) { new The().start(); } } public static class The extends Thread { final Counter c = new Counter(); @Override public synchronized void run() { while (true) { cc(); } } } public static class Counter{ public synchronized void c(){ try { Thread.sleep(1000); System.out.println("qq"); } catch (InterruptedException e) { e.printStackTrace(); } } } }