Q:

print a line for the firstt time and then every 30 minutes

I have a below method which will be called every one minute from background thread.
public void testMethod() {
    // some other code

    System.out.println("hello")

    // some other code
}

Now every one minute, hello line will get printed out. Is there any way, by which hello line should get printed for the first time and then after every half an hour (it doesn't have to be exact half an hour) once testMethod is invoked by background thread. I don't want to use any executors or timer class. 
I just don't want my hello line gets printed out every one minute. In the starting it should print once and then every 30-35 minutes is fine. Is there any other way to do this without using Timer or Executors? Can we not use current time and do some mod check?
I want all other code in testMethod to get executed every one minute so I cannot sleep or anything. I just need to have some random check by which we can decide whether to print hello or not. I just don't want to print hello every one minute.

A:

Have a static member variable for stoping the loop
private static boolean isTrue = true;

public static boolean getIsTrue() {
    return isTrue;
}

public static void setIsTrue(boolean test) {
    YourClass.isTrue = test;
}

Your program should be
    System.out.println("hello");
    Thread printText = new Thread(){
        public void run() {
            while(getIsTrue()) {
                try {
                    Thread.sleep(30*60*1000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                System.out.println("hello");
            }
        }
    };
    printText.start();

When you want to stop your loop
public void testMethod() {
    setIsTrue(false);
}

