Code example for CopyOnWriteArraySet

Methods: sleep

0
    	lockMap.put("t2", new ReentrantLock());
    	lockMap.put("t3", new ReentrantLock());
    } 
     
	public void lock(String str){
		final Set<String> newGroupsOfTopic = new CopyOnWriteArraySet<String>();
        Set<String> groupsOfTopic = this.groupsOfTopics.putIfAbsent(str, newGroupsOfTopic);
        if (null == groupsOfTopic) {
            groupsOfTopic = newGroupsOfTopic;
        } 
 
        lockMap.get(str).lock();
        try { 
			System.out.println("lms" + Thread.currentThread());
			try { 
				Thread.sleep(2000);
			} catch (InterruptedException e) {
				//logger.error("handle error!", e); 
			} 
			System.out.println("lme" + Thread.currentThread());
		}finally{ 
Experience pair programming with AI  Get Codota for Java