Multiple instances of the Application

Hello,

i was looking for the answer of my question on the forum , but i had not found.
When i open my application in another brower, i want a new intance of the Application (but the main point is to have a differente main thread for each use). Is it possible? Where can i change the configuration for that?

Thanks,

Romain

For each session there is one instance of your Application class. If you open the same application in two browsers you will have two different sessions and thus two different Application instances, one per browser. This is what happens by default.

Thanks for your answer!

It’s my source code solution:


public class MyApplication extends Application implements ApplicationContext.TransactionListener {
	...
	private static ThreadLocal<MyApplication> currentApplication = new ThreadLocal<MyApplication>();
	public String IdApplication;

	public static Opticout getCurrentMyApplicationt() {
		return currentApplication.get();
	}

	@Override
	public void transactionStart(Application application, Object transactionData) {
		System.out.println("Loading the threadlocal");
	        if (application == MyApplication.this) {
	            System.out.println("Registering the threadLocal");
	            currentApplication.set(this);
	        }
	    }
	
	@Override
	public void transactionEnd(Application application, Object transactionData) {
		if (application == MyApplication.this) {
	            System.out.println("Unregistering the threadLocal");
	            currentApplication.remove();
	        }
	    }

	@Override
	public void init() {
		...
		getContext().addTransactionListener(this);
	}
...
}

At the beginning i initialise my “IdUser” variable (MyApplication.IdApplication = …).
And after anywhere in my code, i can know which application i use (… = MyApplication.IdApplication)