I'm creating too many threads like this in my App for some testing purposes , but sometimes when i set the number of thread too high it crash with a
java.lang.OutOfMemoryError: at java.lang.Thread.nativeCreate (Thread.java) at java.lang.Thread.start (Thread.java:731)
new Thread(new Runnable() {
@Override
public void run() {
while (!stop) {
}
}
}).start();
How to prevent this bug ? Or how to solve it ? Maybe a Try - Catch can make any work ?