diff options
author | Eike Stepper | 2019-10-09 09:37:18 +0000 |
---|---|---|
committer | Eike Stepper | 2019-10-09 09:37:18 +0000 |
commit | 6fb4124f0ddb0f1992417382b102f1a00163eae3 (patch) | |
tree | 0b575c30775a77629c2ff264bcb4561bc555f33b /plugins | |
parent | 98f932bba689e9ae6b0603d721d8ded22ce16bcc (diff) | |
download | org.eclipse.oomph-6fb4124f0ddb0f1992417382b102f1a00163eae3.tar.gz org.eclipse.oomph-6fb4124f0ddb0f1992417382b102f1a00163eae3.tar.xz org.eclipse.oomph-6fb4124f0ddb0f1992417382b102f1a00163eae3.zip |
[Releng] Add initial OwnershipMapper
Diffstat (limited to 'plugins')
2 files changed, 80 insertions, 22 deletions
diff --git a/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/OwnershipMapper.java b/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/OwnershipMapper.java index b258c70cc..f57fa7984 100644 --- a/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/OwnershipMapper.java +++ b/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/OwnershipMapper.java @@ -11,6 +11,7 @@ package org.eclipse.oomph.setup.internal.installer; import org.eclipse.oomph.util.IOUtil; +import org.eclipse.oomph.util.ThreadPool; import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; @@ -42,10 +43,6 @@ import java.util.List; import java.util.Map; import java.util.Random; import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ThreadFactory; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -69,16 +66,6 @@ public final class OwnershipMapper } }; - private static final ThreadFactory THREAD_FACTORY = new ThreadFactory() - { - public Thread newThread(Runnable r) - { - Thread thread = new Thread(r); - thread.setDaemon(true); - return thread; - } - }; - private static final String PROJECTS_NAME = "projects.txt"; private static final boolean REFRESH_PROJECTS = Boolean.getBoolean("refresh.projects"); @@ -118,9 +105,7 @@ public final class OwnershipMapper stats = new BufferedWriter(new FileWriter("folders.txt")); long start = System.currentTimeMillis(); - - ExecutorService threadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 4, THREAD_FACTORY); - final CountDownLatch finished = new CountDownLatch(topLevelFolders.length); + ThreadPool threadPool = new ThreadPool(); for (final File topLevelFolder : topLevelFolders) { @@ -136,15 +121,11 @@ public final class OwnershipMapper { printStackTrace(ex); } - finally - { - finished.countDown(); - } } }); } - finished.await(); + threadPool.awaitFinished(); writeStats(rootFolder.relativize(rootFolder), start, IGNORE, IGNORE, ROOT); stats.close(); diff --git a/plugins/org.eclipse.oomph.util/src/org/eclipse/oomph/util/ThreadPool.java b/plugins/org.eclipse.oomph.util/src/org/eclipse/oomph/util/ThreadPool.java new file mode 100644 index 000000000..0369cfbad --- /dev/null +++ b/plugins/org.eclipse.oomph.util/src/org/eclipse/oomph/util/ThreadPool.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2019 Eike Stepper (Loehne, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.oomph.util; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * @author Eike Stepper + */ +public class ThreadPool extends ThreadPoolExecutor +{ + private static final int THREAD_COUNT = Runtime.getRuntime().availableProcessors() * 4; + + private static final ThreadFactory THREAD_FACTORY = new ThreadFactory() + { + public Thread newThread(Runnable r) + { + Thread thread = new Thread(r); + thread.setDaemon(true); + return thread; + } + }; + + private final Object lock = new Object(); + + private int executingTasks; + + public ThreadPool() + { + super(THREAD_COUNT, THREAD_COUNT, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), THREAD_FACTORY); + } + + @Override + public void execute(Runnable command) + { + synchronized (lock) + { + ++executingTasks; + } + + super.execute(command); + } + + @Override + protected void afterExecute(Runnable command, Throwable t) + { + synchronized (lock) + { + if (--executingTasks == 0) + { + lock.notifyAll(); + } + } + } + + public void awaitFinished() throws InterruptedException + { + synchronized (lock) + { + while (executingTasks != 0) + { + lock.wait(); + } + } + } +} |