RAP and ThreadLocals [message #527610] |
Thu, 15 April 2010 17:56 |
Benjamin Wolff Messages: 137 Registered: July 2009 |
Senior Member |
|
|
Hi,
i have s question regarding RAP applications and ThreadLocal objects.
At some spots in my application, i use ThreadLocal objects to share these
objects between a user-session(thread). These objects are not synchronized
so i can't use them in a static way. A single object instance for every
object that uses it is too much memory wasted. So i choose the compromise
to use one object per thread thus avoiding expensive synchronization and
not wasting memory.
Is this approach RAP conform?? I know there is a SessionSingletonBase class,
which i also use. But in this case, this has nothing to do with RAP etc.,
so i don't want to build a dependency to RAP API.
For example, i'm using this for SimpleDateFormat and several NumberFormat
instances, which are used in my domain model.
Since i'm not so deep into RAP threading internals, i just wanted to make
sure, that i shouldn't expect any unpredicted behaviour?!
Can in assume, that there is always one user(ui)-thread in RAP unless i create
other threads manually??
please great RAP folks, let thy light of wisdom shine down upon me, so it may
blind my unawareness =))
Greetings,
-ben
|
|
|
Re: RAP and ThreadLocals [message #527693 is a reply to message #527610] |
Fri, 16 April 2010 07:02 |
Stefan Messages: 316 Registered: July 2009 |
Senior Member |
|
|
Hi Benjamin,
as RAP uses the read and dispatch model from SWT you can be sure, that
most of your code that runs within a concrete session context always
runs in the same UIThread.
The only exception I am aware of are ServiceHandlers - they run in a
different thread but still in a session context.
Security frameworks often use a thread-based authentication - in this
case, authenticating the UIThread once on sessions startup (e.g.
#createUI) is sufficient (As an example for the usage of ThreadLocals).
Regards,
Stefan.
Benjamin Wolff schrieb:
> Hi,
>
> i have s question regarding RAP applications and ThreadLocal objects.
> At some spots in my application, i use ThreadLocal objects to share these
> objects between a user-session(thread). These objects are not synchronized
> so i can't use them in a static way. A single object instance for every
> object that uses it is too much memory wasted. So i choose the compromise
> to use one object per thread thus avoiding expensive synchronization and
> not wasting memory.
> Is this approach RAP conform?? I know there is a SessionSingletonBase
> class,
> which i also use. But in this case, this has nothing to do with RAP etc.,
> so i don't want to build a dependency to RAP API.
> For example, i'm using this for SimpleDateFormat and several NumberFormat
> instances, which are used in my domain model.
> Since i'm not so deep into RAP threading internals, i just wanted to make
> sure, that i shouldn't expect any unpredicted behaviour?!
> Can in assume, that there is always one user(ui)-thread in RAP unless i
> create
> other threads manually??
>
> please great RAP folks, let thy light of wisdom shine down upon me, so
> it may
> blind my unawareness =))
>
> Greetings,
> -ben
|
|
|
Powered by
FUDForum. Page generated in 0.03931 seconds