Thread pools

JLupin has built-in mechanism for managing thread pools used in your application for processing (these are different pools than the ones used by server threads). They are standard Java thread pools, so their usage is very simple. JLupin just takes care of creating them and shutting down in proper point of microservice lifecycle.

Configuration

They are configured in microservice configuration file (configuration.yml or servlet_configuration.yml). The configuration sections looks like this:

THREAD_POOLS:
  THREAD_POOL_1:
    size: 8
    waitingTimeForTasksCompletionInMillis: 10000

So above examples defines thread pool named THREAD_POOL_1 with 8 threads and completition time for tasks set to 10000 ms.

Usage

The best option to use such a thread pools is to create proper bean with JLupinClientUtil:

@Bean(name="threadPool1")
public ExecutorService getExecutorService() {
    return JLupinClientUtil.getExecutorServiceByNameManagedByJLupin("THREAD_POOL_1");
}

And then use it inside your code:

@Service("exampleService")
public class ExampleServiceImpl implements ExampleService {
    @Qualifier("threadPool1")
    @Autowired
    private ExecutorService executorService;

    @Override
    public void exampleMethod() throws Throwable {
        executorService.submit(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                // Your computation
                return null;
            }
        });
    }
}