java – Timer for Google App Engine

Question:

The App Engine Whitelist specifies the java.util.Timer class, but as you know, App Engine does not allow new threads to start. Therefore, there is not much sense from java.util.Timer in Whitelist.

Is there some way to organize a primitive timer on Google App Engine?

Answer:

So far, such a primitive version of the timer implementation is working successfully: when the timer start button is pressed for the first time (if this parameter is not set in the session, it is considered that pressing is the first), the current time is recorded in the session:

session.setAttribute("startTime", System.currentTimeMillis())

Then an AJAX poll is organized on the client. At regular intervals, the client sends a request to the server. On the server, the time is determined by an elementary formula:

time = System.currentTimeMillis() - session.getAttribute("startTime")

Thus, it turns out to achieve normal accuracy. And personally to me, such a solution seems more acceptable than a timer on the client side, the value of which is sent to the server as a parameter during the next poll.

Scroll to Top