Something like that should be in another thread. Kicked off in a context listener. You should also make sure you have a solid way of killing this thread from the contextDestroyed method of your listener or make sure you are using daemon threads. Otherwise, you may have trouble reloading your app and/or stopping and restarting you server.
I generally advise against starting your own threads in a webapp unless, you really know what you're doing and can't find any alternative.