javafx中的线程问题。创建多个线程

时间:2018-01-23 12:26:17

标签: java multithreading javafx java-threads

我有javafx的程序,并希望在其他用户插入数据时用新数据刷新列表。所以程序要有实时数据。问题是我创建的线程。每次我打开一个视图时,它都会创建一个新线程并且有多个通知而不是一个。我尝试使用Thread扩展类并实现Runnable,但我没有成功。

在方法初始化时,我有代码,我创建一个runnable并将其设置为线程。

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();

0 个答案:

没有答案
相关问题