Running a regular background event in Java web app

前端 未结 5 573
谎友^
谎友^ 2021-02-04 15:53

In podcast #15, Jeff mentioned he twittered about how to run a regular event in the background as if it was a normal function - unfortunately I can\'t seem to find that through

5条回答
  •  半阙折子戏
    2021-02-04 16:19

    I think developing a custom solution for running background tasks doesn't always worth, so I recommend to use the Quartz Scheduler in Java.

    In your situation (need to run background tasks in a web application) you could use the ServletContextListener included in the distribution to initialize the engine at the startup of your web container.

    After that you have a number of possibilities to start (trigger) your background tasks (jobs), e.g. you can use Calendars or cron-like expressions. In your situation most probably you should settle with SimpleTrigger that lets you run jobs in fixed, regular intervals.

    The jobs themselves can be described easily too in Quartz, however you haven't provided any details about what you need to run, so I can't provide a suggestion in that area.

提交回复
热议问题