In Java, which is considered more taxing? Implementing another thread and using wait notify or incorporating a for/while loop inside a current thread similar to this >
while(running){
//do stuff
if(skip == 20){
//do more stuff
skip = 0;
}else{
skip++;
}
}
I’m gonna guess the latter is not considered best practice but I don’t want to end up spending too much memory on an extra thread that does very little.
(moved to being an answer)
Assuming you have a sleep somewhere or this isn’t an infinite loop … threads are meant for parallelization of work; e.g. you want to do two things at the same time on two different cores. If you don’t need that or it doesn’t apply to your problem, you don’t use additional threads.
If you don’t have a sleep or other blocking operation and it is an infinite loop, you just created a hand warmer app (or a battery drainer app …)