From e97d8f42b64ab091b6bf1c4a1a5b130c3c29e26a Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 3 Apr 2013 17:45:51 +0300 Subject: [PATCH] Updated javadoc to mention runSafely in addition to the manual locking pattern Change-Id: Ia0ddf6149641b8dc609c5c6e53ad569c5bc9c555 --- .../src/com/vaadin/server/VaadinSession.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/server/src/com/vaadin/server/VaadinSession.java b/server/src/com/vaadin/server/VaadinSession.java index 61a3cfb077..844b7ff674 100644 --- a/server/src/com/vaadin/server/VaadinSession.java +++ b/server/src/com/vaadin/server/VaadinSession.java @@ -761,9 +761,25 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { /** * Locks this session to protect its data from concurrent access. Accessing * the UI state from outside the normal request handling should always lock - * the session and unlock it when done. To ensure that the lock is always - * released, you should typically wrap the code in a try block - * and unlock the session in finally: + * the session and unlock it when done. The preferred way to ensure locking + * is done correctly is to wrap your code using + * {@link UI#runSafely(Runnable)} (or + * {@link VaadinSession#runSafely(Runnable)} if you are only touching the + * session and not any UI), e.g.: + * + *
+     * myUI.runSafely(new Runnable() {
+     *     @Override
+     *     public void run() {
+     *         // Here it is safe to update the UI.
+     *         // UI.getCurrent can also be used
+     *         myUI.getContent().setCaption("Changed safely");
+     *     }
+     * });
+     * 
+ * + * If you for whatever reason want to do locking manually, you should do it + * like: * *
      * session.lock();
@@ -773,7 +789,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
      *     session.unlock();
      * }
      * 
- *

+ * * This method will block until the lock can be retrieved. *

* {@link #getLockInstance()} can be used if more control over the locking @@ -781,6 +797,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { * * @see #unlock() * @see #getLockInstance() + * @see #hasLock() */ public void lock() { getLockInstance().lock(); -- 2.39.5