Fixed
Details
Assignee
Anthony WhyteAnthony WhyteReporter
Steve SwinsburgSteve SwinsburgComponents
Fix versions
Priority
Major
Details
Details
Assignee
Anthony Whyte
Anthony WhyteReporter
Steve Swinsburg
Steve SwinsburgComponents
Fix versions
Priority
Created July 18, 2011 at 4:02 AM
Updated September 14, 2015 at 10:46 AM
Resolved May 10, 2013 at 8:28 AM
Maven3 supports parallel builds which can dramatically increase build times. Maven analyses the projects and executes the plugins accordingly. Almost all CPU's are multicored these days and we can take advantage of that to save time on builds.
For example the following command will spawn 4 threads to build:
mvn clean install -T 4
And the following will spawn two threads per cpu core:
mvn clean install -T 2C
Currently you get the following:
[WARNING] *****************************************************************
[WARNING] * Your build is requesting parallel execution, but project *
[WARNING] * contains the following plugin(s) that are not marked as *
[WARNING] * @threadSafe to support parallel building. *
[WARNING] * While this /may/ work fine, please look for plugin updates *
[WARNING] * and/or request plugins be made thread-safe. *
[WARNING] * If reporting an issue, report it against the plugin in *
[WARNING] * question, not against maven-core *
[WARNING] *****************************************************************
[WARNING] The following plugins are not marked @threadSafe in project_name:
[WARNING] org.sakaiproject.maven.plugins:sakai:1.2.0
[WARNING] *****************************************************************
===========================================================================
https://cwiki.apache.org/confluence/display/MAVEN/Parallel+builds+in+Maven+3
Mojo thread safety assertion checklist
Sometimes it can be hard to determine if a plugin and the underlying libraries are thread-safe, so when adding @threadSafe the following checklist can be used:
Check all static fields/variables in plugin/plugin code are not subject to threading problems.
You might want to pay special attention to static member variables of the subclasses of "java.text.Format" (NumeberFormat, DateFormat etc), most of which
are not threadsafe and cannot be shared as static variables.
Check any plexus components.xml; if the components defined are singletons they need to be threadsafe.
Check for presence of known tainted libraries.
Check thread safety of any other third party libraries. This last item can be a bit hard, but inquiries on mailing lists can get you a long way.
This checklist qualifies for a "simple thread safety" review of a mojo.
If a mojo uses a known-non-threadsafe external dependency, you may want to do something like this:
public class MyMojo
extends AbstractMojo
{
private static final Object lock = new Object();
public void execute()
{
synchronized( lock)
{
// Main mojo code
}
}
}