Keeping aside the logic, the technical reason as to why it fails at 10000
is because each thread in Java has a fixed stack size. And when you use 10000 it is unable to find enough memory.
Use -XX:ThreadStackSize=512
to increase the default memory that JVM allocates to threads and it may work. But generally you don't have to bother about it.
On a sidenote check whether you really require recursion over here.