6
I have a multi thread Java system that uses the class ThreadGroup
which is deprecated.
With my current implementation I can’t "kill" a thread in lock either. How to implement efficient code for Thread
in Java?
I need to have at least control over the execution time, startup and completion of my Pool
threaded.
Simplified code of what I need to do more efficiently:
int threadAtivas = 5;
ThreadGroup threadGroup = new ThreadGroup("threads");
while(true){
if(verificaQtdThreadsAtivas(threadGroup)){
criaNovaThread(threadGroup);
}else{
Thread.sleep(1000);
}
}
Related: http://answall.com/q/45320/132
– Victor Stafusa
Can you give more details explaining better what this pool consists of? How it is instantiated and how you use it?
– Victor Stafusa
I improved the question with an example code.
– LeoCBS
Your code example is not good, after all the variable
threadGroup
It’s not being used anywhere, so the simplest suggestion, but which probably serves no purpose in practice, would simply remove the second line of it. In addition to theThread.sleep(1000)
spear oneInterruptedException
. This exception is fundamental to answer your question, and therefore how you are treating it?– Victor Stafusa
I have completed the example. I am not treating the
InterruptedException
, how I should treat?– LeoCBS