0

My Java application in Google App Engine loads a whitelist file stored in /WEB-INF. The file is defined as a resource file in appengine-web.xml:

<resource-files>
    <include path="/whitelist.txt" />
</resource-files>

The whitelist is loaded when the first GET request is received.

However, I want to modify the code such that the whitelist is loaded every 15 minutes. This way if I make any changes to the whitelist file (in WEB-INF/whitelist.txt), the changes are reflected soon after.

I tried using a ScheduledExecutorService with a Runnable task as mentioned here https://stackoverflow.com/a/2249068/1244329 where the task consists of just reading the file. However, the task inside contextInitialized is never executed. In fact, I don't think I am even hitting the contextInitialized method.

What am I doing wrong? How should I implement this?

Community
  • 1
  • 1
BlueChips23
  • 1,861
  • 5
  • 34
  • 53

1 Answers1

1

You could use a cron job to execute the whitelist file loading. See Scheduling Tasks With Cron for Java.

But you have another problem: you can't actually change WEB-INF/whitelist.txt without deploying an updated app code, so you can't actually refresh the whitelist info this way without restarting your app.

You could do it, but by storing the file somwewhere else, where you can update it independently of the app deployment, for example in GCS.

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97