]> source.dussan.org Git - vaadin-framework.git/commitdiff
Attempt to get GAE lock for UIDL requests (#12211)
authorLeif Åstrand <leif@vaadin.com>
Fri, 12 Jul 2013 06:54:06 +0000 (09:54 +0300)
committerVaadin Code Review <review@vaadin.com>
Fri, 12 Jul 2013 09:58:09 +0000 (09:58 +0000)
Also removing the overhead of creating a Date object just for getting a
timestamp in the otherwise touched areas of code.

Change-Id: Ic712c0ae26d22995ad332593dbb8a14dbec7fcd6

server/src/com/vaadin/server/GAEVaadinServlet.java

index b4a83603b05deec38327039fa671782132f7e79f..5a12295d9d5e0417bd38b0ffa5913edfad81fc95 100644 (file)
@@ -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);
                 }
             }