title: Spring Async for batch insertion
body: <p>I'm using spring boot. I was new to spring and started a spring project. So I didn't know about pre defined repositories (JPA, CRUD) which can be easily implemented. In case, I wanted to save a bulk data, so I use <strong><em>for loop</em></strong> and save one by one, Its taking more time. So I tried to use <strong>@Async</strong>. But it doesn't also work, is my concept wrong? </p>
  
  <blockquote>
    <p><strong>@Async</strong> has two limitation</p>
    
    <ul>
    <li>it must be applied to public methods only </li>
    <li>self-invocation – calling the async method from within the same class    won’t work</li>
    </ul>
  </blockquote>
  
  <p><strong>1) Controller</strong></p>
  
  <pre><code>for(i=0;i &lt; array.length();i++){
      // Other codes
      gaugeCategoryService.saveOrUpdate(getEditCategory);
  }
  </code></pre>
  
  <p><strong>2) Dao implementation</strong></p>
  
  <pre><code>@Repository
  public class GaugeCategoryDaoImpl implements GaugeCategoryDao {
      // Other codings
  
      @Async
      @Override   
      public void saveOrUpdate(GaugeCategory GaugeCategory) {
          sessionFactory.getCurrentSession().saveOrUpdate(GaugeCategory);
      }
  }
  </code></pre>
  
  <p>After removing @Async , it working normally. But with that annotation it doesn't work. Is there any alternative method for time consuming? Thanks in advance. </p>