if i have got such java code:
public static void main(String[] args)
{
for(int i = 0;i<100;i++)
{
Future<?> f = ThreadPoolManager.getInstance().schedule(new START(), 500);
f.cancel(true);
}
}
private class START implements Runnable
{
@Override
public void run()
{
System.out.println(1);
}
}
And run it in debug, i can see that all of those threads(after cancel) are still running, so are they taking my memory too? And if yes, how can i destroy those Threads completely?
cancel(true)
callsinterrupt()
on your thread, nothing more. So, you need to handle it properly in yourrun()
method. For your simple case your threads will finish their execution and their objects will be cleared by GC.