Best of Spring FrameworkJuly 2024

  1. 1
    Article
    Avatar of justjavaJust Java·2y

    Java & Spring Best Practices | Strategy Pattern

    The new module in the `java-spring-best-practices` repository focuses on the Strategy Pattern, detailing how to implement it in a Spring application. It emphasizes designing code that is flexible and extensible, helping developers decouple algorithm selection from the main logic. Check out the module for practical examples and contribute to the project on GitHub.

  2. 2
    Article
    Avatar of javarevisitedJavarevisited·2y

    How to use @Transactional annotation like a pro

    Explores advanced usage of the @Transactional annotation in Java Spring microservices to manage concurrency and transactional integrity. Highlights include solving issues with parallel processing in distributed systems, understanding isolation levels, and optimizing transactions. Provides examples with Kafka, PostgreSQL, and Spring Data JPA along with practical tips for using @Transactional effectively.

  3. 3
    Article
    Avatar of justjavaJust Java·2y

    Java & Spring Best Practices | Factory Pattern

    The third module of the java-spring-best-practices repository introduces the Factory Pattern, a design pattern for flexible object creation. Learn how to decouple object creation, enhance scalability, and improve maintainability in your codebase. The module includes practical examples, core principles, benefits, and End-to-End tests for validation.

  4. 4
    Article
    Avatar of netflixNetflix TechBlog·2y

    Java 21 Virtual Threads - Dude, Where’s My Lock?

    Netflix engineers encountered issues with virtual threads in Java 21 causing timeouts and hung instances in their microservices running on SpringBoot 3 and embedded Tomcat. Detailed diagnostics revealed that virtual threads were waiting for reentrant locks, with OS threads pinned and unable to release, leading to a variation of deadlock. The investigation and resolution process underscores the challenges and potential of adopting virtual threads for improved performance.

  5. 5
    Article
    Avatar of javarevisitedJavarevisited·2y

    6 Tips to Avoid NullPointerException in Java

    NullPointerException is a frequent error in Java caused by accessing null references. Preventing this error improves code reliability and maintainability. Key tips include performing null checks, using the equals method correctly, leveraging the Optional class from Java 8, using String.valueOf() and Objects.requireNonNullElse() methods, and opting for primitive types when possible. Annotations and the Bean Validation API in Spring can also help ensure null checks. Implementing these strategies reduces the likelihood of NullPointerException and enhances code robustness.

  6. 6
    Article
    Avatar of hnHacker News·2y

    PostgreSQL and UUID as primary key

    UUIDs are often used as primary keys in databases due to their uniqueness and ease of generation. While not always the optimal choice due to size concerns, PostgreSQL offers a dedicated UUID type that is more efficient than storing UUIDs as text. Experiments show that using the `uuid` type significantly reduces table and index size compared to `text`. Furthermore, UUID v7, which generates time-sorted values, improves insert performance over the more common UUID v4. These optimizations are crucial for large datasets and high-traffic applications.

  7. 7
    Article
    Avatar of justjavaJust Java·2y

    Java & Spring Best Practices | Dependency Injection

    New GitHub repository 'java-spring-best-practices' launched, focusing on Java and Spring best practices through practical code snippets. The first module covers Dependency Injection, highlighting constructor injection for better immutability and testability. Contributions to the repository are encouraged.

  8. 8
    Article
    Avatar of springSpring·2y

    Spring AI with Groq - a blazingly fast AI inference engine

    Spring AI now supports Groq, a fast AI inference engine, by repurposing the existing Spring AI OpenAI Chat client. Developers can leverage Groq's high-performance models for their Spring applications through a familiar API. Key considerations include tool/function calling, API compatibility, model selection, and performance benefits. Groq does not currently support multimodal messages. Stay updated with the latest documentation from Spring AI and Groq for evolving features and compatibility.

  9. 9
    Article
    Avatar of newstackThe New Stack·2y

    How To Test How Much Memory Your Java Application Uses

    Understanding a Java application's memory requirements is crucial for maximizing performance and minimizing operational costs. This guide shows how to use garbage collector (GC) logs to determine the necessary memory size. Key steps include simulating real-world loads, interpreting GC logs, and using tools like JMeter for load testing. Practical examples with the Spring PetClinic application and different Java runtimes are provided to illustrate the process.

  10. 10
    Article
    Avatar of javarevisitedJavarevisited·2y

    Spring Cloud Gateway: The Single Point of Entry or Failure — a Path to Non-Blocking API Gateway

    This post explores the API gateway pattern using Spring Cloud Gateway and Netflix Zuul, highlighting their use cases, benefits, and drawbacks. It delves into the transition from monolithic to microservice architecture, the role of API gateways in client request routing, and the advantages of a non-blocking API gateway. The post also explains filter implementation, service discovery mechanisms, and performance under load conditions. Additionally, it discusses the pros and cons of both gateways, emphasizing the flexibility and modern features of Spring Cloud Gateway.