Java – the thread in GWT, Google App Engine, TimerTask or serviceimpl throws an exception
•
Java
I'm using GWT and Google App Engine I have a series of records. I want to update them every 30 minutes
new Timer().schedule(new TimerTask(){ @Override public void run() { try { Thread.sleep(30000); } catch (InterruptedException e) { e.printStackTrace(); } result = updateFeeds(); } },30000,Long.MAX_VALUE);
When I run the application, when I get:
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.util.List org.joke.planet.client.FeedService.loadFeeds()' threw an unexpected exception: java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)
In the first line or paste the code
My question is how to make a background worker work in the GWT App Engine service?
Solution
You cannot use Java util. Timer, because it will create an ordinary thread, which is not allowed on App Engine However, you can use the background threading tool of the appengine modules API, as follows:
Note that you can only use background threads on manually scaled instances In this example, the background thread prints a message every 30 seconds, always:
Thread thread = ThreadManager.createBackgroundThread(new Runnable() { public void run() { try { while (true) { System.err.println("Doing something!"); Thread.sleep(30_000); } } catch (InterruptedException ex) { } } }); thread.start();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码