Expensive data calculation on the server (architectural question)

Hey all,

i have some issues here and thought about solutions but your input is needed.

Following situation
: From a second party source i get data which i have to link to my database data (=containers) dynamically. So first of all i query my database and then in the memory i compute the link between the database data and the data i got from the second party source ( calculateLinking() ).

The idea
: At the moment this is done at the start for every user after login. Because this results in heavy loading (2 min) i want to do the linking when the application starts the first time and after log in i just link the data reference to the user. In the background there should be periodical update of these data.

The questions

  1. Is this a good idea to handle this situation?
  2. The application init() method gets called whenever a user starts the application (is this correct?). So this could not be the proper place to start the linking. Where can i add my calculateLinking() method when i just want to do it at the first start of the application? The periodical update should be done by a background thread.

Hopefully i provided you with enough information so that you can help me. Otherwise please flame me to post more input.

  • thx

Of course it depends on the kind of data you are going to calculate whether this approach makes sense or not. But it is indeed feasible. You need to overwrite the ApplicationServlet / VaadinServlet (depending on the Vaadin-version you are using) and do the calculation in its init()-method. There you also need to start your background-thread and do the necessary synchronization to assure data-integrity. Note that you are actually not allowed to spawn new thready according to the JEE-spec, so you should use some kind of thread-factory or ExecutorService that gets provided by your App-Server. There is no guarantee that such a thing is available.