Skip to content

Instantly share code, notes, and snippets.

View fmbenhassine's full-sized avatar

Mahmoud Ben Hassine fmbenhassine

View GitHub Profile
@fmbenhassine
fmbenhassine / Main.java
Created March 14, 2025 11:04
#SpringBatch graceful shutdown
package org.example;
import org.postgresql.ds.PGSimpleDataSource;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.launch.JobExecutionNotRunningException;
@fmbenhassine
fmbenhassine / Main.java
Created March 14, 2025 08:40
#SpringBatch concurrent steps with blocking queue reader/writer
package org.example;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.job.builder.FlowBuilder;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.job.flow.Flow;
import org.springframework.batch.core.launch.JobLauncher;
@fmbenhassine
fmbenhassine / Main.java
Created March 14, 2025 08:03
#SpringBatch failed partition restart sample
package org.example;
import org.springframework.batch.core.*;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.partition.support.Partitioner;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.StepBuilder;
@fmbenhassine
fmbenhassine / AggregationJobConfiguration.java
Last active February 9, 2025 09:05
#SpringBatch aggregation job sample
package com.example.demo;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.item.*;
import org.springframework.batch.item.support.IteratorItemReader;
import org.springframework.context.annotation.Bean;
@fmbenhassine
fmbenhassine / DemoApplication.java
Created October 17, 2022 21:18
SF overloaded setter selection
package com.example.demo;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.retry.policy.SimpleRetryPolicy;
public class DemoApplication {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");
SimpleRetryPolicy bean = context.getBean(SimpleRetryPolicy.class);
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
@fmbenhassine
fmbenhassine / MultiResourcePartitionerSample.java
Created November 2, 2020 12:22
#SpringBatch MultiResourcePartitioner job sample
package org.springframework.batch.sample;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepScope;
package org.springframework.batch.sample;
import javax.sql.DataSource;
import javax.xml.bind.annotation.XmlRootElement;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
@fmbenhassine
fmbenhassine / ArchiveRoomRawJson.java
Created June 24, 2020 10:12
#SpringBatch gitter room archiver
package com.example.demo;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.time.Duration;
import java.time.Instant;
@fmbenhassine
fmbenhassine / TestCustomApacheConverter.java
Created March 1, 2020 21:28
Custom Apache beanutils converter with EasyProps
import java.util.Date;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;
import org.jeasy.props.annotations.SystemProperty;
import org.junit.Before;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;