Skip to content

Demonstration of Asynchronous method with Progress tracking in Spring boot

Notifications You must be signed in to change notification settings

jayarathinavel/asyncMethod

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demonstration of Asynchronous method in Spring boot

The idea is to run a method in background which saves a big Excel file to a database, around 10000 rows and track its progress.

How it works ?

  • @EnableAsync is Annotated to the method in service class, which needs to be run in background.
  • The logic while running, just hits the method that is annotated with @EnableSync and moves to next line. Making it run in background.
  • A random id is generated at the starting. After every single row insertion, the progress is saved in database to another table along with the random id.
  • Using the random id, the progress can be retrieved from the database, and can be refreshed after certain intervals and displayed as a progress.

Screenshots

A a dataset of Zomato restaurants from Kaggle is used as a data file. A random id is generated as soon as the method is made to run.

uploadFile.png

With the id generated, another endpoint is run to track the progress.

getProgress.png

Note :

  • The @EnableSync annotated method is to in different class, not in the same class where call the method.
  • SQL Queries for creating the tables and the dataset file is inside the project.
  • The data in progress table is made to delete after completion of the progress, with a sleep time of 10secs.
  • If more time is needed (to mock it as even big process), enable the commented Sleep time in Service.class. It will make process run longer with sleep time in between every row, and can be used for understanding the code flow better

About

Demonstration of Asynchronous method with Progress tracking in Spring boot

Topics

Resources

Stars

Watchers

Forks

Languages