i am working on an application(enterprize application in java) in which i need is single instance to be shared by multiple thread concurrently for which i have used @singleton . when each user login a value is set in telecallers List by invoking setTeleCallersDetails() remote method. but at certain point when number of user logged in exceed 15 then @singleton starts behaving like @stateless bean as setTeleCallersDetails() start adding value in new tellcaller arraylist. can anybody tell to actually how to solve this problem this my code
@Singleton
@Startup
public class UserSessionBean implements UserRemote {
volatile List<UserDetails> user;
volatile List<UserDetails> telecallers;
volatile List notloggedlt;
/**
* Default constructor.
* @return
*/
@PostConstruct
private void startup() {
// TODO Auto-generated constructor stub
if(user == null){
user = new ArrayList<UserDetails>();
}
if(telecallers == null){
telecallers = new ArrayList<UserDetails>();
}
if(notloggedlt == null){
notloggedlt = new ArrayList();
}
}
public List<UserDetails> getUserDetails(){
return user;
}
public List<UserDetails> getTeleCallersDetails(){
return telecallers;
}
public List getNotKLoggedInUsersDetails(){
return notloggedlt;
}
@Lock(LockType.WRITE)
public void setUserDetails(UserDetails objUser){
if(!user.isEmpty()){
Collections.sort(user);
int location = Collections.binarySearch(user, new UserDetails(objUser.getUserId()));
if (location >= 0) {
user.remove(location);
}
}
user.add(objUser);
}
@Lock(LockType.WRITE)
public void removeUserDetails(String userId){
Collections.sort(user);
int location = Collections.binarySearch(user, new UserDetails(userId));
if (location >= 0) {
user.remove(location);
}
}
@Lock(LockType.WRITE)
public void removeTeleCallersDetails(String userId){
Collections.sort(telecallers);
int location = Collections.binarySearch(telecallers, new UserDetails(userId));
if (location >= 0) {
telecallers.remove(location);
}
}
@Lock(LockType.WRITE)
public void setNotKLoggedInUsersDetails(List notloggedusers){
this.notloggedlt = notloggedusers;
}
@Lock(LockType.WRITE)
public void setNotKLoggedInUserDetail(UserDetails objUser){
notloggedlt.add(objUser);
}
@Lock(LockType.WRITE)
public void setTeleCallersDetails(UserDetails objUser){
if(!telecallers.isEmpty()){
Collections.sort(telecallers);
int location = Collections.binarySearch(telecallers, new UserDetails(objUser.getUserId()));
if (location >= 0) {
telecallers.remove(location);
}
}
telecallers.add(objUser);
}
}