Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads in JavaFX

 
Jc Frane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day!

Can I use Thread class in javafx or should I use Task and Service class?

Thank you!
 
Luan Cestari
Ranch Hand
Posts: 163
C++ Redhat Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Which is the propose/job of this new thread that you are going to code? I would say to use Executor (from Java API) using a pool of threads which can be reused.
 
Jc Frane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thank you for the reply.

I am gonna use the code for my school's project. My project includes a module where I want to register new task for each employee and tracking each one of them.
I already managed to write a code where the progressbar is in TableView. I also managed to create Task object and bind its progress to the progressbar.

But I think service will do well with the help of the Executor you are referring with. In oracle documentation it said that it can be restarted and scheduled.

The problem now is, I dont know how to implement Service and Executor.

Would you mind if you provide some sample codes? I will appreciate it so much since I am just a student and found it hard to understand the API documentation.

Thank you so much!
 
Luan Cestari
Ranch Hand
Posts: 163
C++ Redhat Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are some implementation on Java SDK, so you dont need to to create your own implementation or use any external library. One of the JavaDOC of the SDK implementation for example http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledThreadPoolExecutor.html . Another example, showing how would look like the usage of Executor here https://github.com/luan-cestari/SimpleReadFiles/blob/master/src/main/java/com/ourdailycodes/simplereadfiles/main/IOBenchmark.java#L23

Kindest regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic