Björn Björnsen

Greenhorn
+ Follow
since Jan 09, 2024
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
39
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Björn Björnsen

Hi,

I am wondering if it is possible to take this exam at home, in Sweden:
https://shop.oracle.com/apex/f?p=DSTORE:6:366184178546:::6:P6_LPI,P6_PPI,P6_METRIC,P6_TERM:39174374270044710041293161,38441165617256980046634102,Hosted%20Named%20User,6_Month

When I try to buy the voucher, it says some options may not be available in Sweden :-/
Anyone knows why?
And why it is locked to North America?

Thanks in advance.
I am back again

I have created a test class, to kind of simulate what we do in real scenario:



In the result, having parallel stream make the process much more faster.
and Using ExecutorService makes no difference at all.
It looks like having no ExecutorService and just invoke parallel stream does what I need.

What is your idea?
Ok, so I will ignore Stream.parallel and go with ExecutorService.newFixedThreadPool(5)
Ok great,
so it looks like something like Executors.newCashThreadpool and java collection forEach() would be enough for that right?
The reason that I used parallelStream was to make the process faster. (Also number of thread is not important in  Java side, it is oracle side that should be degree 4)
e.g. if copyOnWriteArrayList has about 100 table name to be clean, then do not wait to pick them one by one from the list.
Thanks for the reply,
I am using JDBC to create connection towards Oracle DB.
Inside that method createDbConnectionAndexecuteSqlStatement() it simply create a statement to clean some tables. (and it calls execureUpdate , sorry my bad, it is not execureQuery)
As I mentioned, the sqlStatement part does that cleanup part in parallel with degree (5).
so JDBC asks Oracle to use parallelism in order to run the task.
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?

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.



Thanks everyone for the reply,

Maybe I should give a little more detail:
lets say the service tht is running towards db only, invokes Locker framework, copyOnWritearrayList, ExecutorService  and parallelStream like the code below.



I am not professional in Java concurrence, how much the logic above is close to the solution that you suggested?
If the solution looks feasible, what is your opinion bout fixedThreadPool (5) that matches the sqlStatement parallel degree on db side? should they match, or doesn't mather and cachThreadPool may increase the process Speed there?

Thanks in advance for your reply
Hi everyone,

I have a question about performing several tasks in db, lets say db cleanup, but with parallelStream.

Lets say:

copyOnWritearraylist.parallelStream.forEach(
                    { dbConnectionAndCleanup() } );
...
dbConnectionAndCleanup() {
Try(  var c = getconnection();
        ... ) {
...
PerformDbCleanup();
... }

A lot of data should be cleaned on db, so I am wondering about the best way to improve its performance.
I am not sure opening a connection inside parallelStream is good idea?
Or is there any alternative?

Thanks