Source Code : Timer and TimerTask Classes

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Timer and TimerTask Classes

     
import java.util.Timer;
import java.util.TimerTask;

class GCTask extends TimerTask {
  public void run() {
    System.out.println("Running the scheduled task...");
    System.gc();
  }
}

public class Main {
  public static void main(String[] args) {
    Timer timer = new Timer();
    GCTask task = new GCTask();
    timer.schedule(task, 5000, 5000);
    int counter = 1;
    while (true) {
      try {
        Thread.sleep(500);
      } catch (InterruptedException e) {
      }
    }
  }
}

   
    
    
    
    
  

Thank with us