I have program with javafx and want to refresh list's with new data when other user's insert data. So program to have real-time data. Problems is with thread i created. Every time i open a view it's create a new thread and have multiple notifications instead of one. I tried to extend class with Thread and with implementing Runnable but i had no success.
On method initialize i have code where i create a runnable and set it to thread.
int i = 0;
Runnable br = new Runnable() {
  @Override
  public void run() {
    while (i < i + 1) {
      try {
        Thread.sleep(1000);
        if (count_pacient_number != pjc.getPacientForDoctor(doctor_login).size()) {
          Platform.runLater(new Runnable() {
            @Override
            public void run() {
              emf.getCache().evictAll();
              pacientList.clear();
              patientList();
              count_pacient_number = pjc.getPacientForDoctor(doctor_login).size();
            }
          });
        }
      } catch (InterruptedException ex) {
        ex.printStackTrace();
      }
    }
  }
};
// private Thread thread = null; is created on start of class
thread = new Thread(br);
thread.setDaemon(true);
thread.start();
 
    