Author: markt Date: Sun Sep 23 21:09:22 2012 New Revision: 1389145 URL: http://svn.apache.org/viewvc?rev=1389145&view=rev Log: Some more low(ish) hanging fruit from the allocation hit list. This accounts for ~8% due to the way Thread stores names.
Added: tomcat/trunk/java/org/apache/tomcat/util/collections/ConcurrentWeakHashMap.java (with props) Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?rev=1389145&r1=1389144&r2=1389145&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java (original) +++ tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Sun Sep 23 21:09:22 2012 @@ -42,6 +42,7 @@ import org.apache.tomcat.util.buf.B2CCon import org.apache.tomcat.util.buf.ByteChunk; import org.apache.tomcat.util.buf.CharChunk; import org.apache.tomcat.util.buf.MessageBytes; +import org.apache.tomcat.util.collections.ConcurrentWeakHashMap; import org.apache.tomcat.util.http.Cookies; import org.apache.tomcat.util.http.ServerCookie; import org.apache.tomcat.util.net.SSLSupport; @@ -103,6 +104,9 @@ public class CoyoteAdapter implements Ad private final Connector connector; + private final ConcurrentWeakHashMap<Thread,String> threadNames = + new ConcurrentWeakHashMap<>(); + /** * The string manager for this package. */ @@ -427,7 +431,13 @@ public class CoyoteAdapter implements Ad // Parse and set Catalina and configuration specific // request parameters - req.getRequestProcessor().setWorkerThreadName(Thread.currentThread().getName()); + Thread t = Thread.currentThread(); + String threadName = threadNames.get(t); + if (threadName == null) { + threadName = t.getName(); + threadNames.put(t, threadName); + } + req.getRequestProcessor().setWorkerThreadName(threadName); boolean postParseSuccess = postParseRequest(req, request, res, response); if (postParseSuccess) { //check valves if we support async Added: tomcat/trunk/java/org/apache/tomcat/util/collections/ConcurrentWeakHashMap.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/collections/ConcurrentWeakHashMap.java?rev=1389145&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/collections/ConcurrentWeakHashMap.java (added) +++ tomcat/trunk/java/org/apache/tomcat/util/collections/ConcurrentWeakHashMap.java Sun Sep 23 21:09:22 2012 @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomcat.util.collections; + +import java.util.WeakHashMap; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +/** + * Wraps a WeakHashMap and makes it thread safe when the typical usage is few + * writes and many reads. This class deliberately does not provide access to the + * full Map interface. It only exposes the methods required by Tomcat. + */ +public class ConcurrentWeakHashMap<K,V> { + + private final ReadWriteLock lock = new ReentrantReadWriteLock(); + private final Lock readLock = lock.readLock(); + private final Lock writeLock = lock.writeLock(); + private final WeakHashMap<K,V> map = new WeakHashMap<>(); + + public V get(K k) { + readLock.lock(); + try { + return map.get(k); + } finally { + readLock.unlock(); + } + } + + public V put(K k, V v) { + writeLock.lock(); + try { + return map.put(k, v); + } finally { + writeLock.unlock(); + } + } +} Propchange: tomcat/trunk/java/org/apache/tomcat/util/collections/ConcurrentWeakHashMap.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org