Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,42 @@
</plugins>
</build>

<profiles>
<profile>
<id>jdk21</id>
<activation>
<jdk>[21,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>java21</id>
<goals>
<goal>compile</goal>
</goals>
<phase>compile</phase>
<configuration>
<release>21</release>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java21</compileSourceRoot>
</compileSourceRoots>
<multiReleaseOutput>true</multiReleaseOutput>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>plexus-release</id>
<properties>
<minimalJavaBuildVersion>21</minimalJavaBuildVersion>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.SequenceInputStream;
import java.io.UncheckedIOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.zip.Deflater;
import java.util.zip.ZipEntry;

Expand Down Expand Up @@ -119,8 +118,8 @@ public ConcurrentJarCreator(boolean compressAddedZips, int nThreads) throws IOEx
manifest = createDeferred(defaultSupplier);
directories = createDeferred(defaultSupplier);
synchronousEntries = createDeferred(defaultSupplier);
parallelScatterZipCreator =
new ParallelScatterZipCreator(Executors.newFixedThreadPool(nThreads), defaultSupplier);
parallelScatterZipCreator = new ParallelScatterZipCreator(
ConcurrentJarCreatorExecutorServiceFactory.createExecutorService(nThreads), defaultSupplier);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.codehaus.plexus.archiver.zip;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Classic (pre Java 21) implementation. Create one thread eagerly, but allow pool to scale up to provided
* number (usually set to Java reported CPU count). Apply same thread names as well.
*
* @since 4.10.1
*/
public class ConcurrentJarCreatorExecutorServiceFactory {
private static final AtomicInteger POOL_COUNTER = new AtomicInteger();

static ExecutorService createExecutorService(int poolSize) {
ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
int poolCount = POOL_COUNTER.incrementAndGet();
AtomicInteger threadCounter = new AtomicInteger();
ThreadFactory threadFactory = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread thread =
new Thread(threadGroup, r, "plx-arch-" + poolCount + "-" + threadCounter.incrementAndGet());
thread.setDaemon(true);
return thread;
}
};
return new ThreadPoolExecutor(1, poolSize, 1L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), threadFactory);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.codehaus.plexus.archiver.zip;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Post Java 21 implementation. Create one Virtual Thread per task execution. Apply same thread names as well.
*
* @since 4.10.1
*/
public class ConcurrentJarCreatorExecutorServiceFactory {
private static final AtomicInteger POOL_COUNTER = new AtomicInteger();

static ExecutorService createExecutorService(int poolSize) {
int poolCount = POOL_COUNTER.incrementAndGet();
AtomicInteger threadCounter = new AtomicInteger();
return Executors.newThreadPerTaskExecutor(
Thread.ofVirtual().name("plx-arch-" + poolCount + "-" + threadCounter.incrementAndGet()).factory());
}
}
Loading