title: Spring Boot Custom @Async Wrap Callable
body: <p>I am working on an application that supports multi tenancy. The tenant's unqiue identifier is stored in a thread local and can be accessed via some service.
  To allow parallel processing, I have created a Callable wrapper, sets the thread local variable:</p>
  
  <pre><code>class TenantAwareCallable&lt;T&gt; implements Callable&lt;T&gt; {
    private final String tenantName;
    private final Callable&lt;T&gt; delegate;
  
    TenantAwareCallable(Callable&lt;T&gt; delegate, String tenantName) {
      this.delegate = delegate;
      this.tenantName = tenantName;
    }
  
    @Override
    public T call() throws Exception {
      // set threadlocal
      TenantContext.setCurrentTenantName(tenantName);
  
      try {
        return delegate.call();
      } catch (Exception e) {
       // log and handle
      } finally {
       TenantContext.clear();
      }
    }
  }
  </code></pre>
  
  <p>This can already be used in the application. But what I would like to have is some custom <code>@Async</code> annotation, like for example <code>@TenantAwareAsync</code> or <code>@TenantPreservingAsync</code>, that wraps the callable, created by Spring in this one and then executes it.</p>
  
  <p>Is there some way to get started with this?</p>
  
  <p>Thanks in advance!</p>