0

I'm making a small application at work, thats holds an open eye on ours servers though REST. I'm loading everything fine, and its working as it should.

Altho, i need my application to check the REST every 3-5min, to see if any service is down, or still up and running.
I have tried with Timer, @Schedule and other stuff, but i cant get it to work, so i deleted it from the application again.
But i really need this, so is there a way to do this?
Its the methods loadDataSubs() and loadDataCus() that loads the REST.
Thanks in advance

import java.awt.AWTException;
import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.client.RestTemplate;

import ch.qos.logback.core.joran.action.Action;


public class Setup extends JFrame {

    Subscriberhealth sub = new Subscriberhealth();
    Customerhealth cus = new Customerhealth();
    RestTemplate restTemplate = new RestTemplate();

    public Setup( String title ){
        super( title );

        //checking for support
        if(!SystemTray.isSupported()){
            System.out.println("System tray is not supported !!! ");
            return ;
        }

        setBounds(100, 100, 350, 480);
        setResizable(false);

        getContentPane().setLayout(null);

        loadDataSubs();
        loadDataCus();

        setGui();

        setVisible(true);
        setDefaultCloseOperation(HIDE_ON_CLOSE);

        setupTray();
        setupIcon();
    }

    public void setupIcon(){
        Toolkit kit = Toolkit.getDefaultToolkit();
        Image img = kit.createImage("src/main/resources/6.png");
        setIconImage(img);
    }

    public void loadDataSubs() {
        // Load Sub REST info
        sub = restTemplate.getForObject("https://xxx/health", Subscriberhealth.class);
        System.out.println("TEST 1");
    }

    public void loadDataCus() {
        // Load Cus REST info
        cus = restTemplate.getForObject("https://xxx/health", Customerhealth.class);
        System.out.println("TEST 2");
    }

    public void setupTray(){
        //get the systemTray of the system
        ...
    }


    public void setGui() {
        // setup labels etc.
        ...
    }

}
Patrick R
  • 1,949
  • 3
  • 32
  • 58
  • 2
    Pick a duplicate: http://stackoverflow.com/search?q=schedule+a+task+java –  Oct 01 '15 at 09:57
  • 1
    Low latency, see [*How to Use Swing Timers*](http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html); high latency, see [*Concurrency in Swing*](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/) and. – trashgod Oct 01 '15 at 10:50

0 Answers0