aboutsummaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2013-07-12 09:54:06 +0300
committerVaadin Code Review <review@vaadin.com>2013-07-12 09:58:09 +0000
commit23ed4870339df44d02126fe53c431c8b6282f475 (patch)
tree3b649eb23cd9b3d6a13a7135e95a9489fc38a0ab /server/src
parent94c0f86fafd6808df902af0a4dbccd2b45922ba4 (diff)
downloadvaadin-framework-23ed4870339df44d02126fe53c431c8b6282f475.tar.gz
vaadin-framework-23ed4870339df44d02126fe53c431c8b6282f475.zip
Attempt to get GAE lock for UIDL requests (#12211)
Also removing the overhead of creating a Date object just for getting a timestamp in the otherwise touched areas of code. Change-Id: Ic712c0ae26d22995ad332593dbb8a14dbec7fcd6
Diffstat (limited to 'server/src')
-rw-r--r--server/src/com/vaadin/server/GAEVaadinServlet.java35
1 files changed, 18 insertions, 17 deletions
diff --git a/server/src/com/vaadin/server/GAEVaadinServlet.java b/server/src/com/vaadin/server/GAEVaadinServlet.java
index b4a83603b0..5a12295d9d 100644
--- a/server/src/com/vaadin/server/GAEVaadinServlet.java
+++ b/server/src/com/vaadin/server/GAEVaadinServlet.java
@@ -218,23 +218,24 @@ public class GAEVaadinServlet extends VaadinServlet {
memcache = MemcacheServiceFactory.getMemcacheService();
try {
// try to get lock
- long started = new Date().getTime();
- // non-UIDL requests will try indefinitely
- if (!ServletPortletHelper.isUIDLRequest(request)) {
- while (new Date().getTime() - started < MAX_UIDL_WAIT_MILLISECONDS) {
- locked = memcache.put(mutex, 1,
- Expiration.byDeltaSeconds(40),
- MemcacheService.SetPolicy.ADD_ONLY_IF_NOT_PRESENT);
- if (locked) {
- break;
- }
- try {
- Thread.sleep(RETRY_AFTER_MILLISECONDS);
- } catch (InterruptedException e) {
- getLogger().finer(
- "Thread.sleep() interrupted while waiting for lock. Trying again. "
- + e);
- }
+ long started = System.currentTimeMillis();
+ while (System.currentTimeMillis() - started < MAX_UIDL_WAIT_MILLISECONDS) {
+ locked = memcache.put(mutex, 1, Expiration.byDeltaSeconds(40),
+ MemcacheService.SetPolicy.ADD_ONLY_IF_NOT_PRESENT);
+ if (locked || ServletPortletHelper.isUIDLRequest(request)) {
+ /*
+ * Done if we got a lock. Will also avoid retrying if
+ * there's a UIDL request because those are retried from the
+ * client without keeping the server thread stalled.
+ */
+ break;
+ }
+ try {
+ Thread.sleep(RETRY_AFTER_MILLISECONDS);
+ } catch (InterruptedException e) {
+ getLogger().finer(
+ "Thread.sleep() interrupted while waiting for lock. Trying again. "
+ + e);
}
}