Hi guys,

I have this code to open a browser every 5 seconds, but I can't get it to close after 5 seconds.
Can you guys give me any hints? Thanks a lot!

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;


public class HelloWorld {
public static void main(String[] args) throws InterruptedException {

String url = "www.google.com";

int x = 5;
while (x < 8)
{
Thread.sleep(5000); // define after how many milliseconds new tab will be opened

if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(new URI(url));
} catch (IOException | URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Thread.sleep(5000);
//here I want to quit the browser
}

} else {
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("xdg-open " + url);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Thread.sleep(5000);
}
}
}
}
}