I have a working workaround. If you create a MavenLifecycleParticipant (see http://maven.apache.org/examples/maven-3-lifecycle-extensions.html), it is possible to change the number of threads based on an environment entry:

@Component(role = AbstractMavenLifecycleParticipant.class, hint = "threadNumber")
public class ThreadNumberSetterMavenExtension extends AbstractMavenLifecycleParticipant {
...
    public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
    	int numberOfThreads = 1;
    	String threadNumberPerCoreString = System.getProperty( ENVIRONMENT_ENTRY_FOR_THREAD_NUMBER );
    	if ( threadNumberPerCoreString != null ) {    		
    		try {
    			double threadsPerCoreString = Double.parseDouble( threadNumberPerCoreString );
				numberOfThreads = (int) (threadsPerCoreString * Runtime.getRuntime().availableProcessors());
    		}
    		catch( NumberFormatException e ) {
    			logger.warn( "Invalid number defined as '" + ENVIRONMENT_ENTRY_FOR_THREAD_NUMBER + "' environment entry. Using 1 thread as default.", e );
    		}
    	}
    	logger.info( "Number of build threads: " + numberOfThreads );
    	if ( numberOfThreads > 1 ) {
    		session.getRequest().setBuilderId( "multithreaded" );    		
    	}
    	else {
    		session.getRequest().setBuilderId( "singlethreaded" );
    	}
    	session.getRequest().setDegreeOfConcurrency( numberOfThreads );
	}
...

}
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira

--
You received this message because you are subscribed to the Google Groups "Jenkins Issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to