I'm building a custom image that contains my java app.
Basically I'm calling
mvn clean install
RUN mvn -T 1C clean install
According to my humble opinion I think that build application by maven inside Dockerfile get more issues than benefits.
When you run new build maven cache is empty so your build spend many time to download all dependencis.
Changing threds used by build do not give you any performance boost.
You can try prepare one docker image with maven and try run some maven command to populate maven cache in this image build. Next you use this image as base for your project.
Another solution maybe separate download dependency and build in two RUN, thanks docker cache your next build may be faster.
RUN mvn dependency:go-offline RUN mvn clean install