Announcement Announcement Module
No announcement yet.
TimerTask needing to write web accessible image files Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • TimerTask needing to write web accessible image files

    I have TimerTasks specified in my spring servlet XML configuration using org.springframework.scheduling.timer.TimerFactoryB ean and org.springframework.scheduling.timer.ScheduledTime rTask beans. Everything works perfect. But now I have a TimerTask that needs to create images that will be accessed by that web application the TimerTask is in. How can I find out what directory to write the image files in from within a TimerTask?

    Is this the best way to implement a task that repeats every 10 minutes? I can navigate my way to the webapps directory of tomcat, but I don't know which servlet context the app that called my TimerTask is in.

  • #2

    I dont think so you can know which servlet context it is getting executed automatically, since your time task does not have access to either request or servlet context directly, what you could maybe try is, send some meta information about the context that the time task can use to create the images on the disk under the appropriate webapp.

    the other option is for you to persist the image into a database, and then write a simple controller that takes a image name as a parameter and serve the image to the browser, this option is better in my opinion since lot of security related issues are handled by the RDBMS itself.


    • #3
      Thank you Sami for your reply. It seems like the context should be able to be queried without a servletRequest or servletContext since the code is being executed in this environment, but I guess not . Yes I can pass in the context as a parameter to the TimerTask, I also have to count on tomcat having been executed from 1 particular directory. Not a pleasant workaround in my particular situation, but I appreciate the suggestion.

      Saving the images in the database is not appealing to me, the images will never be altered or queried (aside from their meta-data which is stored in the database). So I want to rely on filesystems' and web servers' caching mechanisms to make this efficient.