JAVAFX Service creates new threads

Kevin Rushforth kevin.rushforth at oracle.com
Sat Sep 6 17:32:46 UTC 2014


This is documented in the API docs for the Service class:

    The Service by default uses a thread pool Executor with some
    unspecified default or maximum thread pool size. This is done so
    that naive code will not completely swamp the system by creating
    thousands of Threads.


You need to specify your own Executor if you want to change this default 
behavior.

-- Kevin



Francisco Javier Godino wrote:
> Hello:
>
> I have a issue with a Service. 
> I developed thisService. 
> It's an extension of Service:
>
>
> public class MostrarImagenesService extends Service{
> ...
>
> @Override
>
>     protected Task createTask() {
>         return new Task() {
>
>             @Override
>             protected Object call() throws Exception {
>
> ......
>
>                 return null;
>                 
>             }
> }
>
>
>
> This is the way that I invoque the service:
>
>
> switch (MostrarImagenesService.getInstance().getState()) {
>
> case READY:
> MostrarImagenesService.getInstance().start();
>    
>
> break;
>
> case SUCCEEDED:
>
>                                     
> MostrarImagenesService.getInstance().restart();
>                                             
>                 break;
>
>         default:
>
>                 log.info("GrabadoraDeImagenesService State: Grabadora en Funcionamiento");
>
> }
>
>
>
> I see this in the log:
>
> [Thread-10] INFO  servicios.MostrarImagenesService  - MostrarImagenesService: call INICIO trama:00552
>
> the second time that i invoque the service:
>
> [Thread-14] INFO  servicios.MostrarImagenesService  - MostrarImagenesService: call INICIO trama:00553
>
> It is running over a new Thread (Thread 14).
>
>
>
> How I can avoid creating new thread?
> This service will be constantly invoked.
> Can this affect the VM?
>
> Thanks
>   


More information about the openjfx-dev mailing list