<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ardil Mohamed on Medium]]></title>
        <description><![CDATA[Stories by Ardil Mohamed on Medium]]></description>
        <link>https://medium.com/@zmardil?source=rss-d8731198435------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Jk5VmKiv8NM6FLib2acriw.jpeg</url>
            <title>Stories by Ardil Mohamed on Medium</title>
            <link>https://medium.com/@zmardil?source=rss-d8731198435------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 06:12:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zmardil/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Spring Cloud Config Server]]></title>
            <link>https://medium.com/@zmardil/spring-cloud-config-server-48a94c59f225?source=rss-d8731198435------2</link>
            <guid isPermaLink="false">https://medium.com/p/48a94c59f225</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[spring-config-server]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Ardil Mohamed]]></dc:creator>
            <pubDate>Wed, 17 Jul 2024 19:59:02 GMT</pubDate>
            <atom:updated>2024-07-19T12:06:38.505Z</atom:updated>
            <content:encoded><![CDATA[<p>This story is a work in progress, stay tuned! 🥁</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*fKhN-Ru-D2_tnIvFtOWK5Q.png" /><figcaption>Spring Cloud Config Server</figcaption></figure><pre>  &lt;dependency&gt;<br>   &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;<br>   &lt;artifactId&gt;spring-cloud-config-server&lt;/artifactId&gt;<br>  &lt;/dependency&gt;</pre><pre>@RestController<br>public class GreetingController {<br><br>    @Value(&quot;${app.greeting: Hello! I&#39;m not from Config server}&quot;)<br>    private String greeting;<br><br>    @GetMapping(&quot;/hi&quot;)<br>    public String greet() {<br>        return greeting;<br>    }<br>}</pre><p>@EnableConfigServer and add dependencies Config Client or microservice</p><pre>  &lt;dependency&gt;<br>   &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>   &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;<br>  &lt;/dependency&gt;<br>  &lt;dependency&gt;<br>   &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;<br>   &lt;artifactId&gt;spring-cloud-starter-config&lt;/artifactId&gt;<br>  &lt;/dependency&gt;<br>  &lt;dependency&gt;<br>   &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>   &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;<br>  &lt;/dependency&gt;</pre><p>add @RefreshScope onto the controller bean to make it dynamically refresh at runtime and any components using the bean would have a new instance on the next call.</p><p>and make sure to expose refresh endpoint via actuator management.endpoints.web.exposure.include=refresh . A POST request with empty body to the microservice would change the properties dynamically. curl -X POST localhost:3000/actuator/refresh</p><p>make sure to encrypt with (JCE) Java Cryptography Encryption, and make sure to have defaults to make it developer friendly for example; config.uri=http:// localhost:${config.port:8888}</p><h4>References</h4><p><a href="https://12factor.net/">The Twelve-Factor App (12factor.net)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48a94c59f225" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Springboot 3.0 features]]></title>
            <link>https://medium.com/@zmardil/springboot-3-0-features-d863dfa8c4ee?source=rss-d8731198435------2</link>
            <guid isPermaLink="false">https://medium.com/p/d863dfa8c4ee</guid>
            <dc:creator><![CDATA[Ardil Mohamed]]></dc:creator>
            <pubDate>Mon, 15 Jul 2024 18:49:20 GMT</pubDate>
            <atom:updated>2024-07-15T18:49:20.120Z</atom:updated>
            <content:encoded><![CDATA[<p>Spring Boot has long been the favorite framework among Java developers. The latest release of Spring Boot 3.0 will further strengthen this position by quantum leaps. This major update brings in a great number of changes and improvements in terms of both bettering developer productivity and application performance. So, let’s look into some of these most exciting changes now.</p><h4>Java 17 Baseline</h4><p>Spring Boot 3.0 raises the baseline to Java 17, letting developers take full advantage of the newest language enhancements and performance improvements in Java. From pattern matching for switch statements to sealed classes, Java 17 brings a sizeable set of improvements that can make your code much more expressive and effective.</p><h4>Java 17 Baseline</h4><p>Spring Boot 3.0 raises the baseline to Java 17, letting developers take full advantage of the newest language enhancements and performance improvements in Java. From pattern matching for switch statements to sealed classes, Java 17 brings a sizeable set of improvements that can make your code much more expressive and effective.</p><h4>Native Image Support</h4><p>Certainly, among the most wanted features is the fact that — by default — it uses native compilation with GraalVM. You will be in a position to compile your Spring Boot applications into the native executables. This comes with humongous runtime improvements in start-up time and memory footprint reduction. For microservices or serverless applications, this may be a game changer.</p><h4>Observability</h4><p>Spring Boot 3.0 leans into the trend towards greater observability through better support for metrics, logging, and tracing. It goes hand in hand with the Micrometer Observation API, making instrumentation easier for your code and insights more actionable into the performance of an application.</p><h4>HTTP Interface</h4><p>It allows for the definition of HTTP clients based on an interface alone with a built-in HTTP interface feature. This declarative model for creating HTTP clients might save tons of boilerplate code and, therefore, make your API integrations much cleaner and more maintainable.</p><h4>Problem Details for HTTP APIs</h4><p>Spring Boot 3.0 introduces support for the RFC 7807 Problem Details specification for error details in HTTP APIs. Several advantages of this standard representation can be realized along the lines of increased coherence and readability in error responses.</p><h4>Improved Authorization Server</h4><p>The introduction of Spring Authorization Server has greatly simplified developing OAuth 2.0 Authorization Servers. It provides a substantial basis for safe authentication and authorization in applications.</p><h4>Jakarta EE 9 +</h4><p>Spring Boot 3.0 has moved over to Jakarta EE 9+, which changes the javax.* namespace to jakarta.*. This inevitably leads to a few code changes but puts Spring Boot in line to take part in the future of enterprise development using Java.</p><p>Spring Boot 3.0 is more than just an incremental update; it’s a significant evolution of the framework. With its focus on modern Java, native compilation, and improved observability, it provides developers with powerful tools to build efficient, scalable, and maintainable applications.</p><p>As you explore these new features, you’ll likely find that Spring Boot 3.0 not only simplifies many aspects of development but also opens up new possibilities for optimizing your applications. Whether you’re building microservices, web applications, or APIs, Spring Boot 3.0 has something exciting to offer.</p><p>Are you ready to upgrade your projects to Spring Boot 3.0? The future of Java development is here, and it’s more promising than ever.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d863dfa8c4ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Service Discovery in Microservices]]></title>
            <link>https://medium.com/@zmardil/service-discovery-in-microservices-4c3d2a5f7449?source=rss-d8731198435------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c3d2a5f7449</guid>
            <category><![CDATA[eureka]]></category>
            <category><![CDATA[spring-cloud-discovery]]></category>
            <category><![CDATA[service-discovery]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Ardil Mohamed]]></dc:creator>
            <pubDate>Mon, 15 Jul 2024 18:23:14 GMT</pubDate>
            <atom:updated>2024-07-19T15:59:00.703Z</atom:updated>
            <content:encoded><![CDATA[<p>As microservices architecture furthers in popularity, the associated challenges of service management increases. Service Discovery is one such highly critical component which aids in keeping your microservices’ ecosystem vibrant and healthy. This provides a means for services to dynamically locate and talk with other services without their network locations hard coded. We will learn Service Discovery and how it can be implemented with Spring Boot in this post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3mJpHPfCQYtmAGXvgpOIjw@2x.png" /></figure><h3>What is Service Discovery?</h3><p>Service Discovery refers to a process of automatic detection of devices and services on a network. Service discovery, in microservices architecture, is about managing how those services will be located and communicated with each other. This removes the need for manual configuration and helps in realizing the goals of dynamic and scalable systems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*PIPIKSLMYyj8ELlbrvsOfg.png" /></figure><h4>Key Concepts of Service Discovery:</h4><ol><li><strong>Service Registry</strong>: A centralized database where services register themselves and their addresses.</li><li><strong>Service Provider</strong>: A service that registers itself with the Service Registry.</li><li><strong>Service Consumer</strong>: A service that queries the Service Registry to find other services to communicate with.</li></ol><h3>Implementing Service Discovery in Spring Boot</h3><p>Spring Boot, combined with Netflix Eureka, provides a powerful solution for Service Discovery in a microservices architecture. We’ll demonstrate this with two services: a Book Service and an Author Service.</p><h4>Setting Up Eureka Server</h4><p>The Eureka Server acts as the Service Registry where all microservices register themselves.</p><p>Create a new Spring Boot project with eureka-server dependency in pom.xml</p><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;<br>    &lt;artifactId&gt;spring-cloud-starter-netflix-eureka-server&lt;/artifactId&gt;<br>&lt;/dependency&gt;</pre><p>Enable Eureka server with @EnableEurekaServer annotation.</p><pre>@SpringBootApplication<br>@EnableEurekaServer<br>public class EurekaServerApplication {<br>    public static void main(String[] args) {<br>        SpringApplication.run(EurekaServerApplication.class, args);<br>    }<br>}</pre><p>Configure application properties in application.properties</p><pre>server:<br>  port: 8761<br>spring:<br>  application:<br>    name: eureka-server<br><br>eureka:<br>  client:<br>    register-with-eureka: false<br>    fetch-registry: false<br>  server:<br>    enable-self-preservation: false</pre><h4>Setting Up Book Service &amp; Author Service</h4><p>Add eureka-client dependency and enable Eureka client with @EnableDiscoveryClient annotation in both services, but make sure to have unique ports and application names on each service.</p><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;<br>    &lt;artifactId&gt;spring-cloud-starter-netflix-eureka-client&lt;/artifactId&gt;<br>&lt;/dependency&gt;</pre><pre>server:<br>  port: 8081<br>spring:<br>  application:<br>    name: book-service<br><br>eureka:<br>  client:<br>    service-url:<br>      defaultZone: http://localhost:8761/eureka/</pre><p>In order to get author details in book service we use RestTemplate and provide URI</p><pre>@RestController<br>public class BookController {<br><br>    @Autowired<br>    private RestTemplate restTemplate;<br><br>    @GetMapping(&quot;/books/{isbn}&quot;)<br>    public String getBookById(@PathVariable String isbn) {<br>        // ...<br>        var author = restTemplate.getForObject(&quot;http://AUTHOR-SERVICE/authors/&quot; + book.authorId, Author.class);<br>    }<br>}</pre><h4>Check Out the Code</h4><p>You can find the complete code for this example on my <a href="https://github.com/zmardil/service-discovery-example">GitHub repository</a>. Feel free to clone, fork, and experiment with the code to understand Service Discovery better.</p><p>Service Discovery in a nutshell, it enables services to dynamically find and communicate with each other. We can use Spring Boot and Netflix Eureka to make the implementation of Service Discovery easier.</p><p>In this article, we implemented a basic Eureka Server and created the Book and Author services that registered themselves in Eureka and discovered each other. The approach not only simplifies managing microservices but also improves the scalability and resilience of solutions.</p><p>Integrating service discovery into your microservices architecture ensures flexibility and maintainability for graceful handling of variations and failures in a system.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c3d2a5f7449" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building resilient and fault-tolerant microservices.]]></title>
            <link>https://medium.com/@zmardil/building-resilient-and-fault-tolerant-microservices-a18eb76e4893?source=rss-d8731198435------2</link>
            <guid isPermaLink="false">https://medium.com/p/a18eb76e4893</guid>
            <category><![CDATA[circuit-breaker]]></category>
            <category><![CDATA[microservice-architecture]]></category>
            <category><![CDATA[fault-tolerance]]></category>
            <category><![CDATA[resilient]]></category>
            <category><![CDATA[spring-cloud]]></category>
            <dc:creator><![CDATA[Ardil Mohamed]]></dc:creator>
            <pubDate>Mon, 15 Jul 2024 10:18:03 GMT</pubDate>
            <atom:updated>2024-07-15T10:18:03.080Z</atom:updated>
            <content:encoded><![CDATA[<p>In distributed systems, microservices architecture became the standard for building scalable and maintainable applications. This also brings new challenges in guaranteeing that the whole system will remain reliable and responsive if any of its components fail. This is where fault tolerance and resilience fit into place.</p><h3>What is Fault Tolerance?</h3><p>Fault tolerance refers to the degree by which a fault in the system cannot stop it from producing correct results. Hardware faults, software bugs, and network glitches are all faults that could appear during processing. The fault-tolerant system is supposed to gracefully detect these failures and handle them without bringing the overall system to a grinding halt.</p><h4>Key Concepts of Fault Tolerance</h4><ol><li><strong>Self-Healing:</strong> Self-detection of failures and recovering automatically without any human intervention.</li><li><strong>Isolation:</strong> This means making sure that when something goes wrong in one part, the system won’t tumble down like a set of falling dominoes (cascading failures).</li><li><strong>Fallbacks:</strong> Providing alternate responses or actions to take in the case of component failure.</li></ol><h3>Implementing Fault Tolerance and Resilience in Microservices</h3><p>Let’s explore some common patterns and tools used to achieve fault tolerance and resilience in a microservices architecture.</p><h4>Circuit Breaker Pattern</h4><p>The Circuit Breaker pattern is a design pattern used to prevent cascading failures in distributed systems. It monitors the calls to a remote service and opens the circuit (stops the calls) if the service fails continuously. After a specified time, it allows a few trial calls to check if the service has recovered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*0qksojBGBdTwEylnzwQyPg.png" /><figcaption>Circuit breaker pattern</figcaption></figure><p>Let&#39;s try implementing Circuit breaker pattern with Spring Boot, Maven and Resilience4j. First add required dependencies in pom.xml.</p><pre> &lt;dependency&gt;<br>    &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;<br>    &lt;artifactId&gt;spring-cloud-starter-circuitbreaker-resilience4j&lt;/artifactId&gt;<br>  &lt;/dependency&gt;</pre><p>Configure properties with application.properties</p><pre>resilience4j.circuitbreaker.instances.exampleCircuitBreaker.slidingWindowSize=5<br>resilience4j.circuitbreaker.instances.exampleCircuitBreaker.permittedNumberOfCallsInHalfOpenState=3<br>resilience4j.circuitbreaker.instances.exampleCircuitBreaker.waitDurationInOpenState=5000</pre><p>Add circuit breaker in your REST controller endpoint with a fallback method.</p><pre>@RestController<br>public class ExampleController {<br><br>    @Autowired<br>    private RestTemplate restTemplate;<br><br>    @Autowired<br>    private CircuitBreakerFactory circuitBreakerFactory;<br><br>    @GetMapping(&quot;/example&quot;)<br>    public String example() {<br>        CircuitBreaker circuitBreaker = circuitBreakerFactory.create(&quot;exampleCircuitBreaker&quot;);<br>        Supplier&lt;String&gt; exampleSupplier = () -&gt; restTemplate.getForObject(&quot;http://example.com&quot;, String.class);<br>        return circuitBreaker.run(exampleSupplier, throwable -&gt; fallbackMethod());<br>    }<br><br>    public String fallbackMethod() {<br>        return &quot;Service is currently unavailable. Please try again later.&quot;;<br>    }<br>}</pre><h4>Retry Pattern</h4><p>The Retry pattern defines the number of retries for any failed operation before abandoning the operation. This pattern is useful for dealing with transient failures such as temporary network outages.</p><p>Let&#39;s go via an example.</p><pre>resilience4j.retry.instances.exampleRetry.maxAttempts=5<br>resilience4j.retry.instances.exampleRetry.waitDuration=500</pre><pre>@RestController<br>public class ExampleController {<br><br>    @Autowired<br>    private RestTemplate restTemplate;<br><br>    @Autowired<br>    private RetryRegistry retryRegistry;<br><br>    @GetMapping(&quot;/example&quot;)<br>    public String example() {<br>        Retry retry = retryRegistry.retry(&quot;exampleRetry&quot;);<br>        Supplier&lt;String&gt; exampleSupplier = () -&gt; restTemplate.getForObject(&quot;http://example.com&quot;, String.class);<br>        return Try.ofSupplier(Retry.decorateSupplier(retry, exampleSupplier))<br>                 .recover(throwable -&gt; fallbackMethod())<br>                 .get();<br>    }<br><br>    public String fallbackMethod() {<br>        return &quot;Service is currently unavailable. Please try again later.&quot;;<br>    }<br>}</pre><h4>Bulkhead Pattern</h4><p>The Bulkhead pattern involves isolating different parts of the system so that a failure in one part does not affect the others. This can be achieved by limiting the number of concurrent calls to a service or by segregating resources.</p><pre>resilience4j.bulkhead.instances.exampleBulkhead.maxConcurrentCalls=10<br>resilience4j.bulkhead.instances.exampleBulkhead.maxWaitDuration=500</pre><pre>@RestController<br>public class ExampleController {<br><br>    @Autowired<br>    private RestTemplate restTemplate;<br><br>    @Autowired<br>    private BulkheadRegistry bulkheadRegistry;<br><br>    @GetMapping(&quot;/example&quot;)<br>    public String example() {<br>        Bulkhead bulkhead = bulkheadRegistry.bulkhead(&quot;exampleBulkhead&quot;);<br>        Supplier&lt;String&gt; exampleSupplier = () -&gt; restTemplate.getForObject(&quot;http://example.com&quot;, String.class);<br>        return bulkhead.executeSupplier(exampleSupplier);<br>    }<br>}</pre><p>Fault tolerance and resilience in the implementation of microservices are very important to enable them to gracefully handle failures. Circuit Breaker, Retry, and Bulkhead patterns with Resilience4j provide a powerful set of mechanisms toward this end.</p><p>Such patterns, applied in your micro-services architecture, will ensure that your system stays reliable and responsive to any unexpected failure. Not only will it enhance the user experience but also help to safeguard the integrity and stability of your application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a18eb76e4893" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s new in Java 22 release?!]]></title>
            <link>https://medium.com/@zmardil/whats-new-in-java-22-release-1f538a0ffe2d?source=rss-d8731198435------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f538a0ffe2d</guid>
            <category><![CDATA[new-features]]></category>
            <category><![CDATA[jakarta]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-22-update]]></category>
            <dc:creator><![CDATA[Ardil Mohamed]]></dc:creator>
            <pubDate>Tue, 02 Jul 2024 20:20:58 GMT</pubDate>
            <atom:updated>2024-07-19T17:41:51.432Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b4r40Smmhh1u0rdY6PpecQ@2x.png" /></figure><h3>Java Language Updates</h3><h4><strong>Unnamed variables and patterns</strong></h4><p>Unnamed variables can be used in places where variables intentions are unambiguous.</p><pre>try { //code }<br>catch (Exception _) {<br>  System.err.println(&quot;Exception occured&quot;);<br>}</pre><h4><strong>Statements before </strong><strong>super() [Preview Feature]</strong></h4><p>The previous version of Java did not allow child classes to implement any statements before invoking super(). In Java 22 it allows statements before invoking super() although we cannot access instance variables or execute methods. This comes in handy when we need to do some validations before calling base constructor.</p><pre>public class Square extends Shape {<br>  int sides; int length; // cannot access these variables<br>  Square(int sides, int length) {<br>    if (sides != 4 &amp;&amp; length &lt;= 0) {<br>      throw new IllegalArgumentException(&quot;Cannot form Square&quot;);<br>    }<br>    super(sides, length);<br>  }<br>}</pre><h4><strong>String Templates [Preview Feature]</strong></h4><p>A few changes were added to this preview feature.</p><pre>int a = …;<br>int b = …;<br>String interpolated = STR.&quot;\{a} times \{b} = \{Math.multiplyExact(a, b)}&quot;;</pre><h4><strong>Implicitly Declared Classes and Instance Main Methods [Preview Feature]</strong></h4><p>Java now supports Implicit declaration of main method instead of standard template. That is, we can compile the code below using just its file name without any class constructs. These unnamed classes reside in an unnamed package, which resides in an unnamed module.</p><pre>void main () {<br>  // code…<br>}</pre><h3><strong>Libraries</strong></h3><h4><strong>Class File API</strong></h4><p>Class File API standardizes the process of reading, parsing, and transforming Java .class files.</p><pre>ClassFile cf = ClassFile.of();<br>ClassModel classModel = cf.parse(PATH);<br>byte[] newBytes = cf.build(classModel.thisClass() .asSymbol(),<br>  classBuilder -&gt; {<br>  for (ClassElement ce : classModel) {<br>    if (!(ce instanceof MethodModel mm &amp;&amp; mm.methodName()<br>    .stringValue()<br>    .startsWith(PREFIX))) {<br>      classBuilder.with(ce);<br>    }<br>  }<br>});</pre><h4><strong>Foreign Function and Memory API</strong></h4><p>The API allows developers to invoke foreign functions outside of JVM ecosystem and access foreign memory.</p><h4><strong>Stream Gatherers</strong></h4><p>Brings new operations to the Stream API</p><pre>public List&lt;List&lt;String&gt;&gt; gatherIntoWindows(List&lt;String&gt; countries) {<br>  List&lt;List&lt;String&gt;&gt; windows = countries.stream()<br>          .gather(Gatherers.windowSliding(3))<br>          .toList();<br>  return windows;<br>}<br>// Input List: List.of(&quot;India&quot;, &quot;Poland&quot;, &quot;UK&quot;, &quot;Australia&quot;, &quot;USA&quot;, &quot;Netherlands&quot;)<br>// Output: [[India, Poland, UK], [Poland, UK, Australia], [UK, Australia, USA], [Australia, USA, Netherlands]]</pre><h4><strong>Structured Concurrency</strong></h4><p>Introduced in Java 21, Structured concurrency exposes a pattern of coding style that aims to reduce drawbacks of concurrent programming.</p><pre>public static &lt;R&gt; R race(Callable&lt;R&gt; task1, Callable&lt;R&gt; task2) throws InterruptedException, ExecutionException {<br>  try (var scope = new StructuredTaskScope.ShutdownOnSuccess&lt;R&gt;()) {<br>    scope.fork(task1);<br>    scope.fork(task2);<br>    scope.join();<br>    return scope.result();<br>  }<br>}</pre><p>Other methods include; fold, mapConcurrent, scan, windowFixed &amp; windowSliding. API also allows to define custom Gatherers.</p><h4><strong>Scoped Values</strong></h4><p>Introduced in Java 21 along with Structured Concurrency, Scoped Values API introduces a new type ScopedValue&lt;&gt;. This allows data to be immutable throughout the thread lifecycle and enables it to be shared and sorted across threads.</p><h3><strong>Tooling updates</strong></h3><h4><strong>Multi-File Source Programs [Preview Feature]</strong></h4><p>Finally, in Java 22 we can launch multiple files source code without compiling. But it’s good to keep these things in mind,</p><ul><li>The compilation order is not guaranteed when classes are scattered across multiple source files.</li><li>The .java files whose classes are referenced by the main program are compiled</li><li>Duplicate classes in source files are not allowed and will error out</li><li>We can pass--class-path option to use pre-compiled programs or libraries</li></ul><h3><strong>Performance</strong></h3><h4><strong>Region Pinning for G1 Garbage Collector</strong></h4><p>Pinning is the process of informing GC not to remove specific critical objects from memory until JVM is instructed to release the object. This removes the need for Java threads to pause the G1 GC.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f538a0ffe2d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All about Garbage Collector]]></title>
            <link>https://medium.com/@zmardil/garbage-c-dc0945b5c58b?source=rss-d8731198435------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc0945b5c58b</guid>
            <dc:creator><![CDATA[Ardil Mohamed]]></dc:creator>
            <pubDate>Sun, 30 Jun 2024 23:49:19 GMT</pubDate>
            <atom:updated>2024-07-01T02:21:49.717Z</atom:updated>
            <content:encoded><![CDATA[<p>In Java we don’t have to worry about memory management as it’s automatically taken care of by the Garbage Collector (GC). Ever wondered how it works?</p><p>Java stores objects in a special memory area called the <strong>heap</strong>, eventually these objects become unused. The GC identifies these objects as no longer accessible (or unreachable) by the program and reclaims the memory occupied by these forgotten objects.</p><p>And object is considered as unreachable if the program does not contain any reference.</p><pre>Foo foo = new Foo();<br>foo = null; // the object is no longer reachable</pre><p>These objects become eligible for garbage collections; other ways in which an object becomes eligible are by reassigning the reference variable or objects that are created inside a method or objects which are isolated.</p><p>Although it&#39;s not recommended, we can request GC to run garbage collection using System.gc() or Runtime.getRuntime().gc().</p><p>Every object inherits the finialize() method from Object class which can be used to perform cleanup activities before the GC destroys the object.</p><pre>protected void finalize() throws Throwable</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc0945b5c58b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What's new in Java Collections?!]]></title>
            <link>https://medium.com/@zmardil/new-improvements-to-collection-in-java-b11734c7360b?source=rss-d8731198435------2</link>
            <guid isPermaLink="false">https://medium.com/p/b11734c7360b</guid>
            <dc:creator><![CDATA[Ardil Mohamed]]></dc:creator>
            <pubDate>Sun, 30 Jun 2024 23:48:16 GMT</pubDate>
            <atom:updated>2024-07-01T02:17:53.520Z</atom:updated>
            <content:encoded><![CDATA[<p>The Java Collection Framework (JCF) packs some versatile classes and interfaces for managing collections of objects. The Java community has contributed regular updates to keep JCF relevant. Let’s explore few of them here,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*9jSMg5YB0-UD8OE3IkqVMg.png" /></figure><p><strong>Stream Collection API</strong>, A major update was introduced in <strong>Java 8</strong> which was a game changer. Streams provide a functional and declarative way to work with collections. On a stream, we can chain <strong>intermediary operations</strong> in a pipeline for the sequence of objects like filter(), sorted() and map() etc. <strong>Terminal operations</strong> are used to return the result which are not processed further. For example, collect(), forEach() and reduce() etc.</p><p>Few other refinements were introduced in <strong>Java 9 </strong>upto <strong>Java 11, </strong>which includes removeIf(), forEachOrdered() intermediary operations and groupingByConcurrent(), toList() were added to the Collectors class for terminal stream operations.</p><pre>List number = Arrays.asList(2,3,4,5);<br>List square = number.stream().map(x-&gt;x*x).collect(Collectors.toList());</pre><p>In <strong>Java 17,</strong> SequencedCollection interface was introduced for accessing first and last element of a collection along with a way to obtain reversed view. SequencedSet and SequencedMap interfaces extends SequencedCollection which offers specific functionalities to sets and maps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b11734c7360b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Concurrency in Java]]></title>
            <link>https://medium.com/@zmardil/ci-cd-with-jenkins-39e4e87c4a60?source=rss-d8731198435------2</link>
            <guid isPermaLink="false">https://medium.com/p/39e4e87c4a60</guid>
            <dc:creator><![CDATA[Ardil Mohamed]]></dc:creator>
            <pubDate>Tue, 25 Jun 2024 20:00:35 GMT</pubDate>
            <atom:updated>2024-06-30T23:46:44.013Z</atom:updated>
            <content:encoded><![CDATA[<p>Programs by default follows a step-by-step process of execution. But, in modern day applications need to be fluid while multi-tasking like updating UI, stream data and perform calculations etc. A way of achieving this fluidity is via concurrency.</p><h3><strong>Ways of Implementing concurrency in Java</strong></h3><p><strong>Multithreading </strong>is a commonly known approach of implementing concurrency in java. A thread is a lightweight process than runs along with other threads within the program. This can be created and managed using Thread class and the Runnable interface.</p><p>The <strong>concurrent utility</strong> package from Java provides a collection of classes and interfaces to simplify concurrency tasks. Behind the scenes it uses Threads. This package can be imported via java.util.concurrent.</p><p><strong>Alternate approaches</strong> include asynchronous (event-driven) programming and parallel programming.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39e4e87c4a60" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GraphQL]]></title>
            <link>https://medium.com/@zmardil/graphql-664fd17fef34?source=rss-d8731198435------2</link>
            <guid isPermaLink="false">https://medium.com/p/664fd17fef34</guid>
            <dc:creator><![CDATA[Ardil Mohamed]]></dc:creator>
            <pubDate>Tue, 25 Jun 2024 16:58:31 GMT</pubDate>
            <atom:updated>2024-07-17T12:38:22.266Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*W_vWkBds7TnUqeSH0eZeAg.png" /></figure><p>A new way to design APIs. Tired of mapping API data to get exactly the desired structure without any fuff!? GraphQL might be the answer.</p><p>Thanks to Meta (or facebook back then) to introducing this specification of designing APIs, it’s already a proven workhorse in the industry. Companies like Meta, Netflix and Airbnb have already adopted this technology.</p><blockquote><a href="https://en.wikipedia.org/wiki/GraphQL">GraphQL is an open-source data query and manipulation language for APIs and a query runtime engine.</a></blockquote><p>There are many implementations of this specification in different languages, which you can find <a href="https://graphql.org/code/">here</a>. In this write we’ll specifically look into GraphQL features using Java via Springboot starter for GraphQL.</p><p>To begin, first we’ll start by defining our schema in schema.graphqls file under src/main/resources/graphql/<em> </em>directory.</p><pre>type Query {<br>    ads: [Ad]<br>    ad(id: ID!): Ad<br>}<br><br>type Mutation {<br>    createAd(adInput: AdInput): Ad<br>}<br><br>input AdInput {<br>  title: String!<br>  content: String<br>  images: [Image]<br>  status: AdStatus!<br>}<br><br>type Ad {<br>    id: ID!<br>    title: String!<br>    content: String<br>    images: [Image]<br>    status: AdStatus!<br>}<br><br>type Image {<br>    url: String!<br>    alt: String<br>}<br><br>enum AdStatus {<br>    PUBLISHED,<br>    DRAFT<br>}</pre><p>The two basic types in graphql are Query and Mutation.<br>Next, define your controller to handle the queries and mutations.</p><pre>@Controller<br>public class AdController {<br>    @QueryMapping<br>    public Iterable&lt;Ad&gt; findAllAds() {<br>        // ...<br>        return ad;<br>    }<br><br>    @QueryMapping<br>    public Optional&lt;Ad&gt; findAdById(@Argument Long id) {<br>        // ...<br>        return ad;<br>    }<br><br>    @MutationMapping<br>    public Ad createAd(@Argument AdInput adInput) {<br>        // ...<br>        return ad;<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=664fd17fef34" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Async vs. Sync APIs]]></title>
            <link>https://medium.com/@zmardil/async-vs-sync-apis-5201dec116fe?source=rss-d8731198435------2</link>
            <guid isPermaLink="false">https://medium.com/p/5201dec116fe</guid>
            <dc:creator><![CDATA[Ardil Mohamed]]></dc:creator>
            <pubDate>Mon, 24 Jun 2024 21:21:18 GMT</pubDate>
            <atom:updated>2024-06-25T17:00:33.425Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*NyAdVlS3yy_18XsGDqUb-w.png" /></figure><p>Synchronous (Sync) and asynchronous (Async) APIs mainly differ in way they communicate with applications. Sync API handles requests one a time while async API handles multiple requests concurrently without blocking. Let’s dig deeper into benefits of one over the other in this article.</p><p>Sync APIs uses traditional protocols like REST and SOAT etc., which makes it simpler to implement. They cannot handle two requests at the same time. Therefore, this may lead to performance issues if a request takes too long.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*FGGfUgxp7LaZjXHFm8FSpQ.png" /></figure><p>On other hand Async APIs can process multiple requests at the same time. Here, the API can handle complex tasks in the background, yet keeping things responsive for simpler ones. As a result, the APIs are more efficient on bandwidth usage. Async APIs can be implemented using protocols like WebHooks, Websockets, <a href="https://medium.com/@zmardil/graphql-664fd17fef34">GraphQL</a> subscriptions and Server-Side Events.</p><p>Although the concept of Async APIs seem to be instrumental, it comes with a cost. Management and design of these APIs can complex and require mechanisms to implement rate limiting, analytics and throttling, likewise securing these APIs can be challenging.</p><p>While Async APIs can be faster, efficient and can offer reliable scaling, Sync APIs are simpler to implement on situations where requests are needed to be processed in a specific order.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5201dec116fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>