Skip to content

This is a POC of multi-thread process that uses a repositoy injection into a Runnable class that executes in a parallel approach.

Notifications You must be signed in to change notification settings

bscpaz/java-multi-thread-script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi-thread with a repository injection POC (proof of concept)

This is a POC of multi-thread process that uses a repositoy injection into a Runnable class that executes in a parallel approach.

Technologies:

  • Java with Spring Boot + JPA;
  • java.util.concurrent.CountDownLatch;
  • java.util.concurrent.ExecutorService;
  • java.util.concurrent.Executors.

Attention points:

  • A regular Runnable class cannot inject Repositories interfaces (@Autowired) in a Spring Boot Application unless you make it as a @Component with @Scope("prototype") to return each Runnable Classe individually.

Example:

/**
 * @author Bruno Paz (bscpaz)
 */

@Component
@Scope("prototype")
public class MyRunnable implements Runnable {
  private CountDownLatch countDownLatch = null;
  private someDto someDto = null;

  @Autowired
  private MyRepository repository;

  public MyRunnable() {
    super();
  }
  
  //Getters ans Setters
  
  @Override
  public void run() {
    // some code...
    
    List<MyEntity> myEntities = repository.findByName(this.someDto.getName());
    
    // more code...
  }
  

About

This is a POC of multi-thread process that uses a repositoy injection into a Runnable class that executes in a parallel approach.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages