title: How to avoid parallel processing of duplicate item in async system in java
body: <p>I have N threads working on M number of messageIds.<br />
  I want if two thread works on same messageId then make them process in synchronize way.
  Below is how code is spawning thread in  Async way.</p>
  <pre><code>@Async(&quot;TaskExecutor&quot;)
  public void process(int messageId) {
     //process messageId
  }
  
  @Bean
  @Qualifier(&quot;TaskExecutor&quot;)
  public ThreadPoolTaskExecutor poolExecutor() {
      ThreadPoolTaskExecutor poolExecutor = new ThreadPoolTaskExecutor();
      poolExecutor.setCorePoolSize(16);
      return poolExecutor;
  }
  </code></pre>