Hashtable issues
Hi,
I am using a lock synch block for my singleton class where i am protecting a Hashtable, but surprisingly even after entering a key value pair and the size being shown as 1, when immediately i try to acces the hashtable it says the size is 0 and returns null for my key ..the code is as given below
public class UserController implements java.io.Serializable
{
private Hashtable<String,UserInterface> UsrStore = new Hashtable<String,UserInterface>();
private static UserController userCont= null;
String uname=null;
String mailId=null;
String phnNo=null;
String addr=null;
String pin=null;
String city=null;
private UserController()
{
//constructor private ...singleton instance
}
public int Store(String key,UserInterface val)
{
int ret = 0;
ReentrantLock lockPut = new ReentrantLock();
lockPut.lock();
try {
UsrStore.put(key, val);
System.out.println("ok put "+key+" val "+((ExUser)val).getUserName()+" size "+UsrStore.size());
ret = 1;
}
catch(Exception err)
{
System.out.println("Error while inserting into hash map "+err);
ret = -1;
}
finally {
lockPut.unlock();
}
return ret;
}
public UserInterface getObj(String key)
{
ReentrantLock lock = new ReentrantLock();
UserInterface EUW = null;
lock.lock();
try {
System.out.println("ok getting "+key);
EUW = UsrStore.get(key);
ExUser es = (ExUser)EUW;
if(es!=null)
System.out.println("the val is "+es.getUserName()+" size "+UsrStore.size());
else
System.out.println("the val is null"+" size "+UsrStore.size());
}
catch(Exception err)
{
System.out.println("Error while getting data from hash map "+err);
}
finally {
lock.unlock();
}
if(EUW!=null){
System.out.println("hooraah returning not null");
return EUW;
}
else{
System.out.println("shit returning not null");
return null;
}
}
public static UserController getInstance()
{
if(userCont == null)
return new UserController();
else
return userCont;
}
}
Store shows the correct value but when i call getObj i get nothing ..pls help

