Jenkins build is getting struck

During some jenkins build cpu percentage is going 99 % and build gets struck.After restarting the build is success.
If it is due infra of the server it happens to every build.but it happening for only few builds.

Can u provide me a solution or suggestion to resolve this issue.

merging the double ask. Please don’t open a new thread if you don’t get a response. People are volunteers and have different knowledge and time abilities. Profiling is a tricky subject. If you need a a rapid response, especially to this complicated subject, I recommend buying support time from a vendor.