Replace remaining usage of LinkedList with ArrayList/ArrayDeque
Closes gh-25650
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,10 +20,11 @@ import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -94,7 +95,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
||||
|
||||
private volatile boolean active = true;
|
||||
|
||||
private final ConcurrentMap<Integer, LinkedList<Session>> cachedSessions = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<Integer, Deque<Session>> cachedSessions = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -186,7 +187,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
||||
this.active = false;
|
||||
|
||||
synchronized (this.cachedSessions) {
|
||||
for (LinkedList<Session> sessionList : this.cachedSessions.values()) {
|
||||
for (Deque<Session> sessionList : this.cachedSessions.values()) {
|
||||
synchronized (sessionList) {
|
||||
for (Session session : sessionList) {
|
||||
try {
|
||||
@@ -216,7 +217,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
LinkedList<Session> sessionList = this.cachedSessions.computeIfAbsent(mode, k -> new LinkedList<>());
|
||||
Deque<Session> sessionList = this.cachedSessions.computeIfAbsent(mode, k -> new ArrayDeque<>());
|
||||
Session session = null;
|
||||
synchronized (sessionList) {
|
||||
if (!sessionList.isEmpty()) {
|
||||
@@ -247,7 +248,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
||||
* @param sessionList the List of cached Sessions that the given Session belongs to
|
||||
* @return the wrapped Session
|
||||
*/
|
||||
protected Session getCachedSessionProxy(Session target, LinkedList<Session> sessionList) {
|
||||
protected Session getCachedSessionProxy(Session target, Deque<Session> sessionList) {
|
||||
List<Class<?>> classes = new ArrayList<>(3);
|
||||
classes.add(SessionProxy.class);
|
||||
if (target instanceof QueueSession) {
|
||||
@@ -268,7 +269,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
||||
|
||||
private final Session target;
|
||||
|
||||
private final LinkedList<Session> sessionList;
|
||||
private final Deque<Session> sessionList;
|
||||
|
||||
private final Map<DestinationCacheKey, MessageProducer> cachedProducers = new HashMap<>();
|
||||
|
||||
@@ -276,7 +277,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
|
||||
|
||||
private boolean transactionOpen = false;
|
||||
|
||||
public CachedSessionInvocationHandler(Session target, LinkedList<Session> sessionList) {
|
||||
public CachedSessionInvocationHandler(Session target, Deque<Session> sessionList) {
|
||||
this.target = target;
|
||||
this.sessionList = sessionList;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,8 +17,9 @@
|
||||
package org.springframework.jms.connection;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jms.Connection;
|
||||
@@ -58,11 +59,11 @@ public class JmsResourceHolder extends ResourceHolderSupport {
|
||||
|
||||
private boolean frozen = false;
|
||||
|
||||
private final LinkedList<Connection> connections = new LinkedList<>();
|
||||
private final Deque<Connection> connections = new ArrayDeque<>();
|
||||
|
||||
private final LinkedList<Session> sessions = new LinkedList<>();
|
||||
private final Deque<Session> sessions = new ArrayDeque<>();
|
||||
|
||||
private final Map<Connection, LinkedList<Session>> sessionsPerConnection = new HashMap<>();
|
||||
private final Map<Connection, Deque<Session>> sessionsPerConnection = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -155,8 +156,8 @@ public class JmsResourceHolder extends ResourceHolderSupport {
|
||||
if (!this.sessions.contains(session)) {
|
||||
this.sessions.add(session);
|
||||
if (connection != null) {
|
||||
LinkedList<Session> sessions =
|
||||
this.sessionsPerConnection.computeIfAbsent(connection, k -> new LinkedList<>());
|
||||
Deque<Session> sessions =
|
||||
this.sessionsPerConnection.computeIfAbsent(connection, k -> new ArrayDeque<>());
|
||||
sessions.add(session);
|
||||
}
|
||||
}
|
||||
@@ -223,7 +224,7 @@ public class JmsResourceHolder extends ResourceHolderSupport {
|
||||
*/
|
||||
@Nullable
|
||||
public <S extends Session> S getSession(Class<S> sessionType, @Nullable Connection connection) {
|
||||
LinkedList<Session> sessions =
|
||||
Deque<Session> sessions =
|
||||
(connection != null ? this.sessionsPerConnection.get(connection) : this.sessions);
|
||||
return CollectionUtils.findValueOfType(sessions, sessionType);
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.jms.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.jms.Connection;
|
||||
@@ -83,7 +83,7 @@ public abstract class AbstractJmsListeningContainer extends JmsDestinationAccess
|
||||
|
||||
private volatile boolean running;
|
||||
|
||||
private final List<Object> pausedTasks = new LinkedList<>();
|
||||
private final List<Object> pausedTasks = new ArrayList<>();
|
||||
|
||||
protected final Object lifecycleMonitor = new Object();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user