Limit number of threads in Java?

I am using Java for making inferences. However, it consumes too many CPU threads, is it possible to set an upper limit like it is possible to do in Python and C++? I cannot find any reference on how to do so.

Thank you, Jakob