0

I have my multi-module webapp with spring, some servlets and hibernation. I have 4 modules:

-model
-Service
-Utils
-Web

It works fine, but, I need to run some code only at the start of the server. Is there any way to execute code only when it runs as -> run on the server but not every time a request is made?

Manu
  • 145
  • 1
  • 9
  • The simplest way is to add `wasCodeExecuted` flag and execute the code is the flag is false resetting the flag to true after executing. – StanislavL Jun 07 '17 at 09:12

1 Answers1

0

The word "server" sometimes is used for the application itself, therefore, I would try to provide an answer for both possible meanings.

If what you mean is: "when the computer starts" (the server holding the application), then there are plenty things you may do, like initHooks or cronjobs

If you mean when your application starts, then you can run some code at the beginning of your application (in java, for example, search for the main() method or the run() method) or in your apache (if you use one) you can do something like this but instead of using the PHP script, use yours :)

Hope it helps!