A question about thread.sleep( )

"The File is stored" message is not displayed on console...

if autosave equals "true", autosave ( ) method must work on... but autosave( ) method doesn't work...why??

public class Main {
 public static boolean autosave = false;
 public static void main(String[] args)
 {
  Thread t1 = new Thread(new ThreadEx1());
  t1.setDaemon(true);
  t1.start();
  for(int i=1; i<=10;i++)
  {
   try {
    Thread.sleep(1000);
   } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   
   autosave=true;
   System.out.println(i);
  }
  System.out.println("Exit the Program");
 }
}


public class ThreadEx1 implements Runnable {

 @Override
 public void run() {
  // TODO Auto-generated method stub
	 
  while(true) {
   if(Main.autosave) { autosave();    }
  }
 }

 public void autosave() {
  System.out.println("The File is stored");
 }

}

Author: seniorsimon33
Login to Answer
Sort By:
Oldest
|
Newest
|
Vote
|
My Answer