Threading Advice

I need to update a local database on a continual basis, e.g. every 10 minutes.

I created a thread which accomplishes this task. However, it causes the system memory and CPU usage to max out, and stay maxed, after a few hours.

I’m not sure if this is a java or Vaadin question, but I’m looking for people’s advice on how I should setup this updating/threading routine.

Is there something I’m missing about de-allocating a thread after it’s done run() ?

Is there a best-practice for how to allow the thread to run as fast as possible while not hindering the performance of the main system?

Thanks for any help you can provide.
-Rich

Hi,

This is more of a Java question than a Vaadin one, yes.

I would create a Runnable implementation that does the database update.
I’d then schedule that task to run every 10 minutes using a
ScheduledExecutorService

Assuming that there should only be one updating thread for all users/sessions (as opposed to one per user/session) you’ll probably want to setup/destroy the ScheduledExecutor with a
ServletContextListener
. If you’re using Spring or Guice you can use a Singleton instead.

HTH,

Cheers,

Charles