Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Paul Clapham wrote:I see more than one question here:
1. Should I use a Stream and call parallelStream for the purpose of creating several threads to run parallel database updates?
2. Should I try to do these database tasks in several threads?
3. Is running database tasks in several threads going to improve performance?
Let me try to respond to those:
1. Personally I would use a more obvious way of creating several threads -- create an ExecutorService and have it create the threads and run the tasks for you. But on the other hand parallelStream will decide on your behalf how many parallel threads it uses. This is good because you don't have to make that decision, but it's also bad because you don't get to make that decision.
2. Databases are designed to receive and process many requests and process them in parallel. It doesn't make a difference that several requests are all coming from you, unless the requests interfere with each other. Presumably when these updates are running, other people should not be using the database to do regular business, but that's true no matter how you run the updates.
3. Impossible to tell. There's a good chance the answer is yes, but a lot depends on how the database is configured.
Paul Clapham wrote:Hopefully you're using a JDBC connection pool as Tim says.
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Björn Björnsen wrote:My question is abut Java side, is it ok to use executeService like that?
I am wondering if you anyone has any idea that creating a service and having parallelStream inside is a good idea for the purpose that I explained or not?
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Björn Björnsen wrote:In the result, having parallel stream make the process much more faster.
and Using ExecutorService makes no difference at all.
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
Paul Anilprem wrote:So, using a copyOnWritearraylist.parallelStream.forEach({ dbConnectionAndCleanup() } ) (copied from your first post) might be a better option than using any kind of thread pool because elements of a parallelStream will be processed by an optimum number of threads.
You got style baby! More than this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|