@@ -0,0 +1,3098 @@
+/**%0A * Licensed to the Austrian Association for Software Tool Integration (AASTI)%0A * under one or more contributor license agreements. See the NOTICE file%0A * distributed with this work for additional information regarding copyright%0A * ownership. The AASTI licenses this file to you under the Apache License,%0A * Version 2.0 (the %22License%22); you may not use this file except in compliance%0A * with the License. You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.openengsb.core.common;%0A%0Aimport java.util.Collection;%0Aimport java.util.HashSet;%0Aimport java.util.UUID;%0Aimport java.util.concurrent.ExecutionException;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.Future;%0A%0Aimport org.apache.commons.lang.StringUtils;%0Aimport org.junit.Test;%0Aimport org.openengsb.core.common.context.ContextHolder;%0Aimport org.openengsb.core.common.util.ThreadLocalUtil;%0A%0Apublic class ThreadLocalUT %7B%0A%0A    private String%5B%5D arr1s = new String%5B1000%5D;%0A    private String%5B%5D arr2s = new String%5B1000%5D;%0A%0A    @Test%0A    public void threadPoolPerformance() throws Exception %7B%0A        generateStrings();%0A        Runnable command = new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                ContextHolder.get().setCurrentContextId(%220%22);%0A                for (int i = 0; i %3C 1000; i++) %7B%0A                    StringUtils.getLevenshteinDistance(arr1s%5Bi%5D, arr2s%5Bi%5D);%0A                %7D%0A            %7D%0A        %7D;%0A%0A        Runnable command2 = new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                for (int i = 0; i %3C 1000; i++) %7B%0A                    StringUtils.getLevenshteinDistance(arr1s%5Bi%5D, arr2s%5Bi%5D);%0A                %7D%0A            %7D%0A        %7D;%0A%0A        ExecutorService pool = Executors.newFixedThreadPool(10);%0A        long start = executeTasks(command, pool);%0A        System.out.println(System.currentTimeMillis() - start);%0A        pool = ThreadLocalUtil.contextAwareExecutor(pool);%0A        start = executeTasks(command2, pool);%0A        System.out.println(System.currentTimeMillis() - start);%0A    %7D%0A%0A    private void generateStrings() %7B%0A        for (int i = 0; i %3C 1000; i++) %7B%0A            arr1s%5Bi%5D = UUID.randomUUID().toString();%0A            arr2s%5Bi%5D = UUID.randomUUID().toString();%0A        %7D%0A    %7D%0A%0A    private long executeTasks(Runnable command, ExecutorService pool) throws InterruptedException, ExecutionException %7B%0A        Collection%3CFuture%3C?%3E%3E futures = new HashSet%3CFuture%3C?%3E%3E();%0A        long start = System.currentTimeMillis();%0A        for (int i = 0; i %3C 1000; i++) %7B%0A            futures.add(pool.submit(command));%0A        %7D%0A        for (Future%3C?%3E f : futures) %7B%0A            f.get();%0A        %7D%0A        return start;%0A    %7D%0A%7D%0A

add performance-test