Skip to main content

Tech Conversant Weekly Dec 05 - Dec 10

Topic: General                                                                                                                Level: All

In this post, we shall catch up on the multi-faceted technological updates that happened over the past week as well as a few that seized my attention,
Java Garbage Collector illustration

The Garbage collector in JVM abstracts away from managing the memory allocation of the Java application by releasing/dereferencing/defragmenting the object allocated in the memory preventing memory leaks and space depletion. Several GC implementations strategically try to balance on the below parameters for optimal performance of GC,
1. Low latency 
2. High Throughput 
3. Efficient resources usage (CPU and memory)
Typical stages involved in the GC are,
1. Mark (Tracing) - the objects are tree represented and from the application root reachable nodes are painted (LIVE) and unreachable (NON-LIVE) are marked for GC.
2. Sweep - Nonlive objects cleared from the heap memory 
3. Compact - Live objects are defragmented adjacently to enable free blocks memory for the new objects 
4. Copy - Categorization of Live and Nonlive objects for GC 
These steps are used in combination by different GC implementations (Serial, Parallel, Concurrent Mark and Sweep, G1, ZGC, Shenandoah)
Further, the GC could process the steps in the below modes as well,
1. Single vs. Multi pass 
2. Serial vs. Parallel 
3. Stop-the-world vs. Concurrent 
Generational heaps determine the Young (Eden & Survivor space) and the Old generation object heaps by frequent GC on Young and tenured on Old. Object becomes eligible for Old gen. transition based on Live set and allocation rate with the JVM arg Xmx specification 
https://www.azul.com/blog/what-should-i-know-about-garbage-collection-as-a-java-developer/

Serialization is a process of representing an object in a specific format document such that it can be stored or transmitted to,
1. Same JVM at different time 
2. Different Remote JVM 
3. Non-JVM Application 
Deserialization is the process of recreating the same serialized object in any JVM context.
The widely adopted serialization formats are,
1. XML 
2. JSON 
Jackson is an external library used for handling Java serialization and deserialization in JSON format. By using the below modules Jackson achieves the context,
1. jackson-core for low-level API streaming and JSON implement 
2. jackson-annotations 
3. jackson-databind for serialization (transitively supports core and annotation modules)
Jackson ObjectMapper relies on the JavaBean definition of a class,
1. getters for serialization 
2. setters for deserialization 
Since Jackson is baselined to JDK 7, new features can be incorporated by specifying the registerModule builder method on ObjectMapper.
Jackson annotations can provide custom JSON field names with JsonProperty.
During Deserialization, Jackson requires a default constructor and setters methods on the JavaBean class, however, this is made redundant by JsonCreator on the constructor with JsonProperty on arguments and getters for serialization.
To eliminate the need for external libraries for JSON serialization and deserialization we have JDK 17, record classes.
Combining record classes with sealed classes provides Java native efficient JSON serialization without reflective proxy deserialization can also be attained.
https://blogs.oracle.com/javamagazine/post/java-json-serialization-jackson 

The times when the Garbage Collector is not able to free the unallocated/unreachable Java Objects from the heap memory then arises the situation of memory leaks.
The GC will be unable to free the objects if there is at least one reference from the Live set heap memory.
Determining the cause of a leak can be performed by,
1. Heap dump - current heap state and kind of objects present 
2. Profiler - how objects are originated 
Async-Profiler, measures actual heap allocations with averaged sampling data. 
After starting our application, execute the profiler shell script with allow and live args to get the allocation profile data which gives us the heap memory leaks for detection.
https://krzysztofslusarski.github.io/2022/11/27/async-live.html

Consuming a REST endpoint with RestTemplate is straightforward, however, accessing a secured REST endpoint requires configuring the RestTemplate with 
1. ClientHttpRequestFactory
2. ClosableHttpClient 
3. SSLConnectionSocketFactory 
4. SSLContext with trustStore URL and password 
Here while creating a secured REST HTTPS endpoint we need to specify certificates stored in src/main/resources/keystore that is a *.p12 file and configure the same in the applications properties file.
On the consumption side, we need to place the client certificate (src/main/resources/keystore that is a *.p12) and utilize it for context building for TLS and SSL connections in turn populating it in the RestTemplate 

 Microservices are needed to communicate with other services to address/handle a specific business request. 

The HTTP communication can be synchronous or asynchronous, as defined by REST web client implementation in Spring.
1. Feign client implementation - Declarative 
2. Web client implementation - Reactive 
Feign client creates a thread per request model and blocks until a response is received.
The web client is a reactive style model, that sends the request and returns a flux publisher and once the response is received it will be delivered to the subscriber function.
https://www.baeldung.com/spring-boot-feignclient-vs-webclient 


The JDK 7 Date API implements the Comparable interface, with comparison returning the difference between the dates (or) the naturalOrder method to return the sorted dates added into a collection via Apache commons DateUtils to add dates to the Date API.
The JDK 8 LocalDate API implements the ChronoLocalDate interface that extends Comparable interface providing compareTo and naturalOrder methods for sorting the dates added via the LocalDate API methods plusXXX().
https://www.baeldung.com/java-max-date-list-streams


Disclaimer: 
This is a personal blog. Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in a professional or personal capacity, unless explicitly stated. Any views or opinions are not intended to malign any religion, ethnic group, club, organization, company, or individual. All content provided on this blog is for informational purposes only. The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.
Downloadable Files and ImagesAny downloadable file, including but not limited to pdfs, docs, jpegs, pngs, is provided at the user’s own risk. The owner will not be liable for any losses, injuries, or damages resulting from a corrupted or damaged file.
  • Comments are welcome. However, the blog owner reserves the right to edit or delete any comments submitted to this blog without notice due to :
  • Comments deemed to be spam or questionable spam.
  • Comments including profanity.
  • Comments containing language or concepts that could be deemed offensive.
  • Comments containing hate speech, credible threats, or direct attacks on an individual or group.
The blog owner is not responsible for the content in the comments. This blog disclaimer is subject to change at any time.

Comments

Popular posts from this blog

Tech Conversant Weekly Jul 03 - Jul 15

Topic: General                                                                                                                                              Level: All Welcome to the world of cutting-edge technology! Every bi-week, we bring you the latest and most incredible advancements in the tech industry that are sure to leave you feeling inspired and empowered. Stay ahead of the game and be the first to know about the newest innovations shaping our world. Discover new ways to improve your daily life, become more efficient, and enjoy new experiences. This time, we've got some exciting news to share with you! Boosting Java startup with Class Data Sharing (CDS) https://www.youtube.com/watch?v=vvlQv1Dh-HU JDK21 LTS Maintenance and Support https://www.youtube.com/watch?v=3bfR22iv8Pc Health checking of multiple cloud applications with Spring Cloud Gateway https://spring.io/blog/2023/07/05/active-health-check-strategies-with-spring-cloud-gateway Functional Style Non-reactive HTTP clie

Tech Conversant Weekly Jun 19 - Jul 01

Topic: General                                                                                                                                              Level: All Welcome to the world of cutting-edge technology! Every bi-week, we bring you the latest and most incredible advancements in the tech industry that are sure to leave you feeling inspired and empowered. Stay ahead of the game and be the first to know about the newest innovations shaping our world. Discover new ways to improve your daily life, become more efficient, and enjoy new experiences. This time, we've got some exciting news to share with you! Modelling common behaviors between the List and the Set interface has been partially provided by LinkedHashSet. Now from JDK21 with the new interface SequencedCollection extending the Collection interface and is also extended by the List, SortedSet via SequencedSet (for reversal operation), Deque. The SequencedMap interface extends the Map interface by providing the below me

Microservices - Design Patterns

Topic: Software Design                                                                                                        Level: Intermediate Microservices - What? Microservice is a software design methodology, delegated to perform an isolated decoupled single functionality (following the Single-Responsibility Principle from object-oriented SOLID design principles).  Moreover, microservices by design, are decoupled making it easy to develop, test, maintain, deploy, configure, monitor and scale modules independently. Microservices - Why? Having one microservice would not be helpful without it being able to interact with other microservices, to aid in bringing an end-to-end business solution. So arises a question, how can I design a software system that is resilient, decentralized, fault-tolerant, scalable, maintainable, and extensible that complies with the microservice architecture? Design Patterns - What? Design patterns are solutions for commonly occurring problems within a given