java

java
package com.example.demo.feature;

import org.togglz.core.Feature;
import org.togglz.core.annotation.EnabledByDefault;
import org.togglz.core.annotation.Label;
import org.togglz.core.context.FeatureContext;

Feature flags for gradual rollouts

java feature-flags togglz
by David Kumar 4 tabs
java
package com.example.demo.batch;

import com.example.demo.model.User;
import com.example.demo.model.UserDTO;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;

Batch processing with Spring Batch

java spring-batch batch-processing
by David Kumar 2 tabs
java
package com.example.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;

CORS configuration for cross-origin requests

java spring-boot cors
by David Kumar 2 tabs
java
package com.example.rates.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.web.client.RestTemplate;

Retrying a Flaky External API with Spring Retry @Retryable and @Recover Fallback

spring-boot spring-retry resilience
by codesnips 4 tabs
java
package com.example.feed;

import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.Base64;

Keyset (Cursor) Pagination with Spring Data JPA and Base64 Cursors

spring spring-data jpa
by codesnips 3 tabs
java
package com.example.demo.interceptor;

import io.github.bucket4j.Bandwidth;
import io.github.bucket4j.Bucket;
import io.github.bucket4j.Refill;
import jakarta.servlet.http.HttpServletRequest;

Rate limiting and API throttling

java rate-limiting bucket4j
by David Kumar 3 tabs
java
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Currency;
import java.util.Objects;

public final class Money {

Immutable Value Object with a Fluent Builder and build()-Time Validation in Java

builder-pattern immutability value-object
by codesnips 3 tabs
java
public class ProductAggregator implements AutoCloseable {

    private final RemoteServices services;
    private final ExecutorService pool = Executors.newFixedThreadPool(8);

    public ProductAggregator(RemoteServices services) {

Coordinate Parallel Remote Lookups With CompletableFuture in Java

java completablefuture concurrency
by codesnips 3 tabs
java
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.Instant;

Nightly Cleanup of Expired Refresh Tokens with Spring @Scheduled and a Bulk Delete Query

spring-boot scheduling cron
by codesnips 4 tabs
java
package com.example.storage;

import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;

Bind and Validate Grouped App Settings with @ConfigurationProperties in Spring Boot

spring-boot configuration validation
by codesnips 3 tabs
java
@RestController
@RequestMapping("/api/transactions")
public class TransactionExportController {

    private final CsvExportService exportService;

Stream a Large CSV Export to the HTTP Response with StreamingResponseBody in Spring Boot

spring-boot streaming csv
by codesnips 3 tabs
java
package com.example.demo.service;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
import org.springframework.stereotype.Service;

Actuator for production monitoring

java spring-boot actuator
by David Kumar 4 tabs