GWT, Google App Engine, TimerTask or Thread in ServiceImpl throw exception

前端 未结 5 1646
星月不相逢
星月不相逢 2021-01-18 07:53

I am using GWT and Google App Engine. I have array of records and I want to update them every 30 mins. In the ServiceImpl I have the fallowing code :



        
5条回答
  •  清歌不尽
    2021-01-18 08:24

    You sir, could benefit from appengine's newish ThreadManager class.

    https://developers.google.com/appengine/docs/java/backends/overview#background_threads

    Use ThreadManager.currentRequestThreadFactory() to get a Thread factory which will interrupt spawned threads as soon as the current request is finished, and ThreadManager.backgroundThreadFactory() to spawn threads that will last as long as you please (but only works on backends)

    For frontend requests, it is recommended to keep track of your threads, and call thread.join() if you want them to finish before appengine's request filter interrupts them.

提交回复
热议问题