You're welcome.

-- Kevin


Francisco Javier Godino wrote:
Hi Kevin:

It was resolved with your help.
I included this lines:

ExecutorService executorService = Executors.newSingleThreadExecutor();

CapturadoraDeImagenService.getInstance().setExecutor(executorService);

Thanks a lot!

Francisco Javier





On Saturday, September 6, 2014 2:32 PM, Kevin Rushforth <[email protected]> wrote:


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


Reply via email to