I'm running a RESTful java backend on GlassFish. Attached to that is an HTML5 / JS frontend which I can put in a webapp project (and then include the backend as a dependency), or run on an IIS webserver on a different location. CORS is not an issue. Whatever solves this following problem:
Situation:
- User1 logs on and database path is set to 'db/user1/'
- User1 inserts 'Value 1' into the database
- User2 logs on and database path is set to 'db/user2/'
- User1 tries to delete 'Value 1' from database
User1 would not be able to delete Value 1 from db/user1, since the databasepath has been changed to db/user2 and there is no Value 1 in that database.
public class DataAccess{
private static DataAccess dataaccess;
private String databasepath;
public static DataAccess getInstance() {
if (dataaccess == null) {
dataaccess = new DataAccess();
}
}
}
How can I modify the getInstance() method so that it acts as a singleton, but only inside the thread of that user? I saw something called threadlocal but didn't fully understand it, is that perhaps a solution?
Any help is most certainly appreciated.