From: Leif Åstrand Date: Fri, 12 Jul 2013 06:54:06 +0000 (+0300) Subject: Attempt to get GAE lock for UIDL requests (#12211) X-Git-Tag: 7.1.1~9 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=23ed4870339df44d02126fe53c431c8b6282f475;p=vaadin-framework.git 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 --- 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); } }