Closed andreykirson closed 3 years ago
Hello again Andrey!
Yes, for sure!
Are you interested in the overall idea of having a Scheduler that can allocate a thread for blocking JDBC calls from a dedicated pool of treads, or any specific construction in the code in the book that implements the usage of the approach?
If you switch to a Fully Non-blocking code with SpringWebflux, you get the benefit of coding without using block(). If you choose to remain JPA, consider using R2Dbc libraries to working in a Non-blocking mode.
Or you can do this instead: Mono.fromCallable(jpafunctionCall).publishOn(Scheduler);
Configure your Scheduler before injecting it. I can't show that part of the code here.
You will get a Mono...learn more about Flux and Mono with SpringWebflux. Unfortunately, the book is not a fully functional Spring Reactor material, just pseudo form of it.
Hello Magnus.
I am interested in optimization for Scheduler in ReviewService how to determine optimal values of threadPoolSize and taskQueueSize?
If you already configured the Scheduler you injected using ExecutorService and ThreadPool, then the rest will be to adjust your ThreadPool size till you get an optimal state.
If you have not done a Custom configuration of your Scheduler, then let me know maybe I will try share a code that does that. Then you can tweak the ThreadPool sizes and TaskQueue size to fit your goal.
Oluwagbemiga Adebowale hello. If you don't mind, could you share this code for optimization?
In order to know what you are doing, I will leave space for you to do your own Research.
Note that to create a Scheduler, there is Factory class called: Schedulers. It has a static method, #fromExecutor. Scheduler newScheduler = Schedulers.fromExecutor(executor);
Note that the method takes an ExecutorService instance as a parameter. There are several ways to create an ExecutorService instance.
Check out the Executors class API. For instance, there is "Executors.newCachedThreadPool" that takes a ThreadFactory instance.
Like this: ExecutorService executorService = Executors.newCachedThreadPool(threadFactory);
Now, lastly..there are several free threadFactory instance code online from open source projects. An example is: BasicThreadFactory from "org.apache.commons.lang3.concurrent.BasicThreadFactory"
..you will need to customize this to your case. Google more on that online.
Above all, you can avoid all this steps and it's strongly advised bcos the lifecycle of the threads and pool will have to be managed by you, instead just do this:
ExecutorService executorService = Executors.newFixedThreadPool(threadSize, threadFactory);
And use the resultant executorService in your Schedulers.fromExecutor(executorService);
I hope that helps? done!
@cometbid-project Thanks for helping out!
@andreykirson Have your questions been answered?
@cometbid-project thank you for your explanation. If I understand you correctly, I should use Little's law and the like further to optimize the size of the thread pool, right?
Closing this issue due to inactivity, please open it again if the above suggestions regarding the use of the Schedular for JPA blocking code aren't sufficient!
Good afternoon!
Would you mind give a link where can I read about the optimization of Schedular for JPA blocking code?