How it works...

The only case where you should use threads in an enterprise context, if you really want to use them, is when the application server creates the thread. Here, we ask the container to do so using factory:

Resource(name = "LocalManagedThreadFactory")
private ManagedThreadFactory factory;

Using some functional-style code, we create our thread:

Thread thread = factory.newThread(() -> {
response.resume(Response.ok(userBean.getUser()).build());
});

Now, moving on to the managed stuff, we can set the name and priority of the thread that we just created, as follows:

thread.setName("Managed Async Task");
thread.setPriority(Thread.MIN_PRIORITY);

Don't forget to ask the container to start the thread:

thread.start();
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.41.187