Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!

Tony Evans

Ranch Hand
+ Follow
since Jun 29, 2002
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
7
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tony Evans

Hi thanks for the replies, I think raw performance is my number one priority,  especially now working in the cloud we are loading huge amounts of data into collections, and every bit of performance you can squeeze out is important.
I dont think loops are that hard to read and maintain. When streaming first came out, like many others I mistook stream for speed.
1 week ago
I like the look of streams, they look neat, dare I say sexy. But from a performance point of view I have found loops are better. Now we have moved into NoSql we are ending up with huge amounts of data to throw around. So apart from a very few cases such as in concurrency issues, using Maps. I have gone back to loops.
So my point is thinking totally in terms of performance, if performance is something that you are thinking of, its best to use loops.

So purely thinking in terms of performance ,  can anyone think of a case where they would use a stream rather than a loop. A case I have is an a example



Which I use to handle a race condition

I hope this stimulates a debate, although I am sure it has been debated before.
1 week ago
What I enjoy about Java, is there are always new things to learn, what I dislike about exams is you have to remember stuff you dont really use anymore. I did a coding example recently and it was all based on JPA one to one, many, many to many, all good solid stuff. But the problem was it was solid stuff from 4 years ago, since for the last 4 years I have been working on NoSQL.
Ok forget those entities to make it bidirectional @JoinColumn should be in the ManyToOne

so thsi works birectional




Thanks for the reply I overwrote Equals and Hash for both entities still not updating account with FundCav2



Hi

Playing around with SpringData JPA, I have a problem with OneToMany JoinColumn

In the following code


return data for account is  : AccountFund [acountId=1111, accountName=AccountCavanagh, funds=[Fund [fundId=111110, fundName=FundCav1]]]

Returning the data for both funds I have :
Fund [fundId=111110, fundName=FundCav1]
Fund [fundId=111111, fundName=FundCav2]

so the fund data is being added to the repo, but FundCav2 is not being added to the FundAccount set.  

My Question is when  I use a JoinColumn do I have to take the account out of repo and add it then save it.

With MappedBy the code above would add the FundCav" to the set, I would think using  JoinColumn it would handle adding to the set the same way through the fundrepo





Thanks for any help
2 weeks ago
Hi I am trying to test bidirectiona. I am using spring CrudRepository

I have created two entities



And




running the test


Brings back customer and a null for customerAddress

3 weeks ago
Fixed change application to

[code]
spring.h2.console.enabled=true
spring.h2.console.path=/h2_console
spring.datasource.url=jdbc:h2:file:~/h2/testdb
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.hibernate.ddl-auto = update
spring.jpa.show-sql=true
[code]

Maven and Gradle is now working
3 weeks ago
I have 2 identical projects both springboot testing against a H2 Databse Maven works Gradle Fails  on Table not found








Pom.xml from Maven


The only difference for Gradle is of course I used a gradle build



I run a SpringBootTest Maven passes  Gradle gives me Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "FUND" not found; SQL statement:



3 weeks ago
Hi yes Paul, was right I made the mistake of using one lock per thread. One lock per instance. Sometime you forget the basics for those who want to see computeIfAbsent in action




Thank you very much for this nugget  computeIfAbsent(key, k -> new LongAdder()).increment()
Thanks for all the very informative replies.

Paul Clapham yes when you wrote "You have to synchronize on the object which you want to control access to". Yes this makes perfect sense. Its what I thought was the problem.

Thank you everyone.
The Map is passed in via the constructor i picked a random word and outputted it and the thread its on

Thread 1 dancer 0
Thread 4 dancer 0
Thread 3 dancer 0
Thread 5 dancer 1
Thread 2 dancer 1



so it looks as if synchronized(this) is being ignored, since for that word wordcount should be 0 for Thread 1
1 month ago
I have a ConcurrentHashMap which my code shares with a numerous threads. The functionality reads and counts words. And stores the results in a Map , the key is the word the value is the count

Now  I know that ConcurrentHashMap will not handle race conditions. You can get the case of one thread overwriting another thread word counter.

So I went for synchronized

But found the following does not work, if you hammer it


I can handle race conditions  by locking the whole collection


Also fails on race conditions


What I would like to know is why does synchronized(this) and lock.lock(); fail on race conditions. From all the documents I have read they should work.
1 month ago
Simple question but I cant seem to find the answer on Google. I am starting tomcat on a linux box using catalina.bat jpda run this is great for development.
But now I need to start tomcat, and close the shell I use.

Uisng catalina.bat jpda run if I close the shell it stops the tomcat instance.

Would I be right in thinking I should be using catalina.bat jpda start.

Thanks for any help.
5 months ago