⚠️#Spring Data JPA Performance Tip:⚠️
Mark the transaction handling class with @Transactional(readOnly=true) and mark modifying methods as just @Transactional. ReadOnly disables dirty-checking on read-only methods and speeds up your application. 👇
As a bonus, you get extra protection from modifying any entities in read-only methods by calling their setters unintentionally. Example:
Institutions will try to preserve the problem to which they are the solution.
-- Clay Shirky
👇
The Shirky Principle suggests that complex solutions - a company, an industry, or a technology - can become so focused on the problem that they are solving, that they can inadvertently perpetuate the problem itself.
This may be deliberate (a company striving to find new nuances to a problem which justify continued development of a solution), or inadvertent (being unable or unwilling to accept or build a solution which solves the problem completely or obviates it).
I wouldn't say I like @Transactional spring tests and don't recommend using them. I prefer cleaning/populating db with @Sql annotation. To do this I usually create 2 files:
📍resources/clear.sql
📍resources/insert_data.sql
👇
Learning #Java is a never-ending story for me: I just learned about " double-brace initialization", which creates an anonymous class derived from the specified class (the outer braces), and provides an initialiser block within that class (the inner braces). e.g. 👇
For example, this code:
List<Integer> l = new ArrayList<>();
l.add(1);
l.add(2);
May look like:
new ArrayList<Integer>() {{
add(1);
add(2);
}};
Or it may look like constructor with named parameters:
public class User {
String name;
String surname;
String email;
}
User user = new User() {{
name = "John";
surname = "Doe";
}};
The Pareto Principle suggests that in some cases, the majority of results come from a minority of inputs: 👇
📍80% of a certain piece of software can be written in 20% of the total allocated time (conversely, the hardest 20% of the code takes 80% of the time)
📍20% of the effort produces 80% of the result
📍20% of the work creates 80% of the revenue
📍20% of the bugs cause 80% of the crashes
📍20% of the features cause 80% of the usage
A management concept developed by Scott Adams (creator of the Dilbert comic strip), the Dilbert Principle is inspired by The Peter Principle.
Under the Dilbert Principle, employees who were never competent are promoted to management in order to limit the damage they can do. Adams first explained the principle in a 1995 Wall Street Journal article, and expanded upon it in his 1996 business book, The Dilbert Principle.
Today I decided to check the performance of different ways of converting an int variable to a String object in Java. 🧵👇
I searched on Stackoverflow:
📍Integer.toString(i)
📍"" +i
📍String.valueOf(i)
📍new StringBuilder().append(i).toString() - a bit strange way, but it was one of the suggestions😄
I have implemented 4 benchmarks using the JMH framework (see pictures).