Last active
March 1, 2020 21:16
-
-
Save ThomasVitale/e3f5aaff857e9ae373a83d48fd6dfd1f to your computer and use it in GitHub Desktop.
Multitenancy Stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.thomasvitale.application; | |
import com.thomasvitale.application.multitenancy.TenantContext; | |
import org.junit.jupiter.api.Test; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
public class ThreadTest { | |
@Test | |
public void testThread() { | |
TenantContext.setCurrentTenant("TENANT_ARGUS"); | |
System.out.println("(Main) SET Thread name: " + Thread.currentThread().getName() + ", tenantId: " + TenantContext.getCurrentTenant()); | |
ExecutorService executor = Executors.newCachedThreadPool(); | |
for (int i=0; i<10; i++) { | |
executor.submit(new AsyncTaskParent()); | |
} | |
TenantContext.clear(); | |
System.out.println("(Main) CLEAR Thread name: " + Thread.currentThread().getName() + ", tenantId: " + TenantContext.getCurrentTenant()); | |
executor.shutdown(); | |
} | |
static class AsyncTaskParent implements Runnable { | |
@Override | |
public void run() { | |
System.out.println("(AsyncParent) SET Thread name: " + Thread.currentThread().getName() + ", tenantId: " + TenantContext.getCurrentTenant()); | |
ExecutorService executor = Executors.newCachedThreadPool(); | |
executor.submit(new AsyncTask()); | |
TenantContext.clear(); | |
System.out.println("(AsyncParent) CLEAR Thread name: " + Thread.currentThread().getName() + ", tenantId: " + TenantContext.getCurrentTenant()); | |
executor.shutdown(); | |
} | |
} | |
static class AsyncTask implements Runnable { | |
@Override | |
public void run() { | |
System.out.println("(Async) SET Thread name: " + Thread.currentThread().getName() + ", tenantId: " + TenantContext.getCurrentTenant()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment