Michael Sims
Norm Radder wrote:Could you post a small, complete program that compiles, executes and shows the problem for testing?
Michael Sims
Stephan van Hulst wrote:That's way too much code that's not related to the problem
Stephan van Hulst wrote:I'm also not sure why you would start a separate thread just to have tasks executed by an executor service. Why are you creating task, and why are you running it in a thread?
Michael Sims
Dave Tolls wrote:You're adding (in the second example) stuff to the Scene (via the GridPane)
Dave Tolls wrote:If you have to update the UI in the worker thread(s) then you need to use Platform.runLater.
Dave Tolls wrote:However, you should not need to do this with a ProgressBar, if you follow the above document.
Michael Sims
Stephan van Hulst wrote:Submitting tasks to an ExecutorService takes almost no time, and will not freeze your UI.
Stephan van Hulst wrote:In your application, make executor an instance field
Stephan van Hulst wrote:and from startTasks() you can just execute the for-loop that submits all the tasks to the executor without having to use another surrounding task to do it.
Michael Sims
Dave Tolls wrote:Have a read of how to use Tasks and ProgressBars.
Michael Sims
Stephan van Hulst wrote:In general, your application should have only one ExecutorService, and you should pass it to classes that need to perform tasks in the background.
Michael Sims
Michael D Sims wrote:Ok, am I passing the ExecutorService to classes? OR Am I passing classes to the ExecutorService (presumably to have those classes executed in the background)?
Stephan van Hulst wrote:the executor is passed to the BackgroundTaskExample class, because it needs it to run its background tasks. It passes background tasks to the executor to run.
Michael Sims
Stephan van Hulst wrote:Here's a small example of a class that has an executor and performs tasks in the background:
Michael Sims
Michael D Sims wrote:
My original code has this:
Which IntelliJ must have added for me because I didn't put it there. When I built the shortened example, the compiler was getting hung up on it, so I removed it and it worked.
Dave Tolls wrote:And you really should look at using the ProgressBar properly.
Michael Sims
Stephan van Hulst wrote:Operations on graphical components always need to be done on the Event Dispatch Thread. For JavaFX, you do that by calling Platform.runLater() and supply it a task that needs to be run on the EDT.
Stephan van Hulst wrote:There's an easier way to report progress though. JavaFX has a class Task which contains a progress property.
Michael Sims
Michael D Sims wrote:OK, you lost me ... EDT?
I'm VERY familiar with binding progress bar to the progressProperty.
But that has to be done in a task, and the example you gave me for using an executor was specifically NOT a task.
However, I seem to have massaged that class you gave me into a task that executor runs via the method you showed me ... still playing with it, but I think it's going to work.
Stephan van Hulst wrote:
Michael D Sims wrote:OK, you lost me ... EDT?
Event Dispatch Thread. In JavaFX it is also called the application thread, I believe?
Stephan van Hulst wrote:
Michael D Sims wrote:I'm VERY familiar with binding progress bar to the progressProperty.
In your original code you didn't bind it though. Instead, you just set the progress on the bar directly, which is not allowed from any thread other than the EDT.
Stephan van Hulst wrote:
Michael D Sims wrote:However, I seem to have massaged that class you gave me into a task that executor runs via the method you showed me ... still playing with it, but I think it's going to work.
Cool, show us what you've managed to do when you're ready.
Michael Sims