Code example for ConcurrentHashMap

Methods: putIfAbsent

0
			new ConcurrentHashMap<String, UserAccount>(); 
	 
	public void setAccount(String userName, UserAccount account) { 
		accounts.putIfAbsent(userName, account); 
		if (account.getAccountAlias() != null) { 
		    accountAliases.putIfAbsent(account.getAccountAlias(), account); 
		} 
	} 
	 
	public UserAccount getAccount(String name) { 
		return accounts.get(name); 
	} 
	 
	public UserAccount getAccountWithAlias(String alias) { 
		return accountAliases.get(alias); 
	} 
	 
	public UserAccount removeAccount(String name) { 
		UserAccount account = accounts.remove(name); 
		if (account != null && account.getAccountAlias() != null) { 
			accountAliases.remove(account.getAccountAlias());