You can achieve it partially with JVM (Java Virtual Machine) arguments - you can set stack size for thread and heap size for JVM. But there is no possibility of limit memory for each thread. Is there a way to put maximum memory usage limit on each thread in Java?
It's not possible also to limit CPU usage Limiting java application's memory and cpu usage
You can set threads priorities in Java program via setPriority()
in Thread class - but it's awful and really not effective.
You can also spawn things that are now thread as separate process (not separate thread) - with fixed heap size and custom process priority (cpu usage). But you have to make multiprocesess communication effective, what require some knowledge (don't write it on you own, use some already battle tested messaging system). This solution require probably huge changes in your current code.
Text bellow is personal opinion
Whenever you have application where you have to set priorities via some magic (manually or in code) there is 99% of chance that application architecture is broken by design.
But WHY?
Well, people who made JVM spent years developing the most effective thread management solution. You should admit that JVM knows better how to handle it.