public static void main(String[] args) { boolean t=false; long cuTime = System.currentTimeMillis(); while(t==false) { System.out.println(cuTime); long g=cuTime+2000; long ct2=System.currentTimeMillis(); if(ct2>=g) { System.out.println(ct2-cuTime); //action here t=true; } }
I tried this and it includes a while loop. therefor the whole program has to wait until this while loop executes. So the entire program slows down. Is there any way to do this without a while loop