GCTask.java Source code

Java tutorial

Introduction

Here is the source code for GCTask.java

Source

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) {
            }
        }
    }
}