From 23ed4870339df44d02126fe53c431c8b6282f475 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Fri, 12 Jul 2013 09:54:06 +0300 Subject: [PATCH] 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 --- .../com/vaadin/server/GAEVaadinServlet.java | 35 ++++++++++--------- 1 file 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); } } -- 2.39.5