Frage

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 .

War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top