Files
  • Main.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.concurrent.TimeUnit;

class Main {
    public static void main(String[] args) {
            // Thread runs alongside program without freezing
            String[] retrievalArary = new String[20];
        	Thread thread = new Thread(new Runnable() {
		        public void run() {
                    for (int i = 0; i < retrievalArary.length; i++) { // Run for the same count as you have items in your array
                    try {
						TimeUnit.SECONDS.sleep(5); // Sleeps the thread for five seconds
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
                        retrievalArary[i] = Integer.toString(i); // Add the integer run count to the array
                        System.out.println(i); // Show progress
                    }
                    
                }
            });
            thread.start();

    }
}