Stopping Thread in Java

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?

Answers


cancel(true) calls interrupt() on your thread, nothing more. So, you need to handle it properly in your run() method. For your simple case your threads will finish their execution and their objects will be cleared by GC.


Need Your Help

ICA online learning for large dataset in scikit

python numpy machine-learning computer-vision scikit-learn

I have a large dataset and am tryng to get gabor filters from images. When the dataset gets too big there are memory errors.

Using Javascript variable in Twig template using Silex framework

php javascript jquery twig silex

I am trying to create a route inside of some Javascript inside of a Twig template and need to use a JS variable as a value to a route parameter.