如何完成springframework ConcurrentTaskScheduler

时间:2014-03-21 09:40:21

标签: java spring

这可能是一个显而易见的问题,但如何完成ConcurrentTaskSchedulerorg.springframework.scheduling.concurrent.ConcurrentTaskScheduler)?我正在这样开始他们:

readConfig();
makeThreads();

for (HTTPEngineThread thread : threads)
{
    ConcurrentTaskScheduler taskExecutorHTTP = new ConcurrentTaskScheduler();
    taskExecutorHTTP.scheduleAtFixedRate(thread, getFrequency() * 1000);
}

当我关闭Tomcat时,大约需要30秒,我得到了这个:

 org.apache.catalina.loader.WebappClassLoader.clearReferencesThreads The web application [/mywebapp] appears to have started a thread named [pool-2-thread-1] but has failed to stop it. This is very likely to create a memory leak.

我猜这是任务调度程序,但我找不到任何方法可以很好地杀死它。我的线程本身没有任何循环,只需运行调度程序每个间隔调用一次的方法。

编辑:根据要求,这里是HTTPEngineThread(除了用一些测试数据更新数据对象之外,它实际上没有做任何事情)。

package com.williamhill.monitoring.statscreen.engines;

import com.williamhill.monitoring.statscreen.query.HTTPQuery;
import com.williamhill.monitoring.statscreen.query.Value;

import org.apache.log4j.Logger;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL; 
public class HTTPEngineThread implements Runnable
{
    private HTTPQuery query;
    private String queryURL;
    private final Logger log = Logger.getLogger("StatsHTTPEngineCatgory");
    private int frequency;
    private final String USER_AGENT = "Mozilla/5.0";

    public HTTPEngineThread(String queryURL, HTTPQuery query, int frequency)
    {
        this.queryURL = queryURL;
        this.query = query;
        query.add(new Value("Test", 1, 1));
    }

    public void run()
    {
        updateData();
    }

    public void destroy()
    {
    }

    public int getFrequency()
    {
        return this.frequency;
    }

    private void updateData()
    {
        try
        {   
            //Actual work will go here when I've written it (doing an HTTP get)
            query.getValue("Test").update("1");
        }
        catch(Exception e)
        {
            log.error("Exception in HTTPEngineThread querying '" + queryURL + "'", e);
        }
    }
}

0 个答案:

没有答案