Search code examples
javajavafxscheduledexecutorservicejavafx-webengine

Periodic web pages loading


I am developing a bot in java and I need it to periodically load a web page with all its javascript computed. To do so, I am using ScheduledExecutorService and JavaFX WebEngine. My scheduled service works very well, it has been tested with logs but once I add the page loading with WebEngine, it suddently stops the scheduled service...

Before the service, I'm using a different WebEngine object to get the urls used in it. That code prints me "Executed!" one time and stops. But if I delete the row with "engine.load(..." it prints executed every 5 seconds

Here's the code for my service:

    ScheduledExecutorService updateService = Executors.newScheduledThreadPool(5);
    WebEngine engine = this.updateEngine;

    ScheduledFuture scheduledFuture = 
            updateService.scheduleWithFixedDelay(new Runnable(){
                @Override
                public void run() { 
                    System.out.println("Executed!");
                    Maj job = jobsCycle.getNextMaj();


                    engine.load(job.getURL());

                }
            },
            0,
            5,
            TimeUnit.SECONDS
            );

Thank you for your help, and if you don't know how to solve it, I am open to any other solution for that task.


Solution

  • Thank you so much for your help guys !!! -_-

    Finally I solved that problem by using Selenium instead of JavaFX WebEngine. That is a little slower but js loading and rendering is managed automatically when loading a web page with HtmlUnit.

    Peace