문제

I am trying to launch a background thread in the start of my javaFX application, but my UserInterface(UI) freezes nevertheless. this is what i am doing :

Task task = new Task<Void>() {
    @Override protected Void call() throws Exception {         
            Platform.runLater(new Runnable() {
        @Override
        public void run() {
            try {

                Class.forName("org.sqlite.JDBC");
                Connection c = DriverManager.getConnection("jdbc:sqlite:visuAgent.db");
                c.setAutoCommit(false);
                Statement stmtt = c.createStatement();

                ResultSet rs = stmtt.executeQuery( "select max(num_step) from avoir_continent " );               
                rs.close();
                stmtt.close();

            } catch (ClassNotFoundException ex) {
                Logger.getLogger(rafraichirbd.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(rafraichirbd.class.getName()).log(Level.SEVERE, null, ex);
            }        
        }
   });       
        return null;
    }
};  

                Thread th = new Thread(task);
                th.setDaemon(true);
                th.start(); 

Any idea ?thank you .

도움이 되었습니까?

해결책

You are using Platform.runLater() inside your Task's call(). The Platform.runLater() takes you back to the UI thread.

Try removing it, while doing the computation and use it only when you need to update some data on the UI

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top