I used below code to test multi-thread, in the run method of ThreadDemo, I added Thread.sleep(milliseconds) method, but this will cause no output. After removing this method, it works fine. Anybody can help explain this behavior?
import java.util.concurrent.*;
public class ThreadTest {
    private static ThreadLocal<Long> counter = new ThreadLocal<>();
public static void main(String[] args) {
    System.out.println("test start");
    counter.set(0l);
    int count = 3;
    ExecutorService executorService = Executors.newFixedThreadPool(count);
    for(int i=0;i<count;i++) {
        String name = "thread-"+i;
        executorService.submit(new ThreadDemo(name,counter));
    }
    System.out.println("test end");
}
public static class ThreadDemo implements Runnable{
    private String name;
    private ThreadLocal<Long> counter;
    public ThreadDemo(String name, ThreadLocal<Long> counter) {
        this.name = name;
        this.counter = counter;
    }
    public void run() {
        while(true) {
        Long val = (counter.get()  == null) ? 1 : ((counter.get()+1)%10);
        counter.set(val);
        System.out.println("name: "+this.name+" val "+val);
        Thread.sleep(10);
        }
    }
}
}
 
     
     
     
    