Understanding the Error
The OutOfMemoryError thrown appears not because of insufficient heap memory but due to the following reasons:
Excessive Thread Creation
If the application creates too many threads, it may reach a limit where no more threads can be created. In such cases, it is crucial to investigate the stack trace thrown with the error and reduce the number of thread creations at the application code level.