首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不工作的spring异步超时

不工作的spring异步超时
EN

Stack Overflow用户
提问于 2013-10-02 16:27:05
回答 1查看 4.8K关注 0票数 0

我在Spring配置中添加了以下内容。我假设默认的超时值是以秒为单位的,所以我设置了三分钟。我设置了一个异步任务来睡眠当前线程5分钟。我触发异步任务并运行到完成,没有异常或中断。我做错了什么?

代码语言:javascript
复制
<mvc:annotation-driven>
        <mvc:async-support default-timeout="180"/>
</mvc:annotation-driven>

下面是我调用的异步方法:

代码语言:javascript
复制
@Async
    public void generateIDOIncentiveFiles(String sessionId, String userId) throws Exception
    {
        final long SLEEP_TIME_MILLS = 5 * 60 * 1000;

        try
        {
            // Get the job entry from the JOBS table
            Job job = jobsDao.getJob(RequestHelper.JOB_IDO_INCENTIVES);

            // Check to see if the job is enabled.
            if ( job.isEnabled() == false )
                throw new Exception ( "Job is not enabled" );

            // Check to see if the job is already running.

            if ( job.isRunning() )
                throw new Exception ( "Job is running" );

            // Start the timer
            StopWatch sw = new StopWatch();
            sw.start();

            // Capture the date/time when the job was started
            Date jobStartDate = new Date();

            LOG.debug("Starting IDO Incentives Extract process..." );

            String jobCurrentStatus = "running";
            String jobLastRunMsg = "Job started";
            Date jobLastRunDate = new Date();

            jobsDao.updateJobStarted(userId, RequestHelper.JOB_IDO_INCENTIVES, jobLastRunDate, jobLastRunMsg, jobCurrentStatus);

            LOG.debug("Sleeping for five minutes..." );

            Thread.sleep(SLEEP_TIME_MILLS);

            LOG.debug("Back from sleep." );

            jobCurrentStatus = "idle";

            // Capture the date/time when the job ended
            sw.stop();
            double elapsedTime = sw.getTotalTimeSeconds();
            int elapsedTimeMinutes = (int) (elapsedTime / 60);
            Date jobEndDate = new Date();

            jobsDao.updateJobComplete(RequestHelper.JOB_IDO_INCENTIVES, "", "idle");

            // Add entry to JOB_HISTORY table

            LOG.debug("Updating job history..." );

            JobHistory jobHistory = new JobHistory();

            jobHistory.setFile_name("file name");
            jobHistory.setFile_path("file path");
            jobHistory.setElapsed_time(elapsedTimeMinutes);
            jobHistory.setEnd_date(jobEndDate);
            jobHistory.setJob_name(RequestHelper.JOB_IDO_INCENTIVES);
            jobHistory.setStart_date(jobStartDate);
            jobHistory.setStatus("Success");
            jobHistory.setUserid(userId);

            jobHistoryDao.insertJobHistory(jobHistory);

            LOG.debug("Job complete" );

        }
        catch (InterruptedException e)
        {
          e.printStackTrace(); 
        }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-02 18:13:49

就像我想的那样。这个

代码语言:javascript
复制
<mvc:annotation-driven>
    <mvc:async-support default-timeout="180"/>
</mvc:annotation-driven>

这里的async-support@Async无关。这和Servlet 3异步请求处理。有关

无法为@Async方法提供超时值。看看这个答案,看看如何真正做到这一点。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19141922

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档