Hi everybody.
I have a question: My code produces only 1's. Does it show that processor can only do one task at a time or it is just simply becouse I made something wrong?
import java.lang.Thread;
public class SleepThread implements Runnable{
public final int sleepTime = 1000;
public String str = new String();
public SleepThread(String name) {
str=name;
}
public void run() {
try {
Thread.sleep(sleepTime);
}
catch(InterruptedException e) {
System.out.println("Thread was interrupted");
}
}
public static void main(String[] args) {
Thread task1 = new Thread(new SleepThread("task1"));
task1.start();
while(task1.isAlive()) {
int i=0;
i++;
System.out.println(i);
}
}
}