Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从数据库读取数据,同时显示进度指示器_Java_Multithreading_Progress Bar - Fatal编程技术网

Java 从数据库读取数据,同时显示进度指示器

Java 从数据库读取数据,同时显示进度指示器,java,multithreading,progress-bar,Java,Multithreading,Progress Bar,我需要在从数据库读取数据时显示进度指示器的帮助。我所做的一个例子在一个新线程的中间被中断,并继续运行一个主线程。当主线程执行到结束时,另一个线程继续执行。这里面缺少什么 private void loadingData() throws InterruptedException{ prgIndLogin.setVisible(true); prgIndLogin.setProgress(-1); Thread newThrd = new Thread(new Runn

我需要在从数据库读取数据时显示进度指示器的帮助。我所做的一个例子在一个新线程的中间被中断,并继续运行一个主线程。当主线程执行到结束时,另一个线程继续执行。这里面缺少什么

private void loadingData() throws InterruptedException{

    prgIndLogin.setVisible(true);
    prgIndLogin.setProgress(-1);

    Thread newThrd = new Thread(new Runnable() {
        @Override
        public void run() {


            try {
                KorisnikJpaController korCont = new KorisnikJpaController(Persistence.createEntityManagerFactory("LawOfficeV2PU"));
                EntityManager em = korCont.getEntityManager();

                logedUser = (Korisnik) em.createNamedQuery("Korisnik.findByUsernameAndPassword")
                                        .setParameter("usernamekor", tbxUsername.getText())
                                        .setParameter("passwordkor", passField.getText())
                                        .getSingleResult();

                em.close();
                status=true;
            } catch(Exception e) {
                status = false;
                e.printStackTrace();
            } finally {
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        prgIndLogin.setVisible(false);
                    }
                });
            }
        }
    });
    newThrd.start();

}

tbh如果登录需要进度条,您需要修复登录代码。。。除此之外,不清楚您正在尝试做什么&行为与您期望的行为有何不同我正在尝试在从数据库读取数据时显示进度指示器。如果字段“status”为true,则允许验证是否存在用户,否则显示警告。。。在上述情况下,实现与数据库的连接但不立即执行查询,而是在执行主线程后返回并执行线程。我想把上面的方法立即提交到最后,我可能会得到信息。。。。