I am trying to write a server-side component of a GWT application which should pull an XML file every 3 minutes and keep a Hashtable up to date after parsing the XML.
After some research, I set up the thread using ScheduledThreadPoolExecutor
stationParser = new TFLStationsParserThread(bikeStations);
scheduler.scheduleWithFixedDelay(stationParser, 2, 180, SECONDS);
The TFLStationsParserThread has a minimal constructor, and this run() method
public void run() {
System.out.println("TFLStationsParserThread run()");
stationParser.refreshStationData(stations);
}
The stationParser eventually gets the data with the following command
HTTPResponse response = URLFetchServiceFactory.getURLFetchService().fetch(request);
Here is my problem: When this .fetch() is run from within a ScheduledThreadPoolExecutor I get the following error
com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'urlfetch' or call 'Fetch()' was not found.
at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:98)
at com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:37)
at couk.mtaylor.bikes.server.TFLStationsParser.refreshStationData(TFLStationsParser.java:66)
at couk.mtaylor.bikes.server.TFLStationsParserThread.run(TFLStationsParserThread.java:35)
...
If I comment out the scheduleWithFixedDelay scheduler and call refreshStationData directly then I get no such issue.
This leads me to believe that the thread is missing some required GWT libraries, but this is beyond my knowledge and I cannot find any solutions online that are helping.
Why would I be getting these GWT error messages from within a scheduled thread but not when I call the method directly?
I cannot confirm this, but I think this might be GAE’s way of telling me this is not how to do threads in GAE. The code works fine if I remove GAE from the buildpath and stop using .fetch().
For now I’m dropping the idea of writing for GAE while I get more used to Java.