Yes or No: Will Singleton-izing my "Resources" offer tangible performance gains??

50 views
Skip to first unread message

karthik reddy

unread,
Jul 6, 2011, 11:31:31 PM7/6/11
to google-we...@googlegroups.com
I use my Resources.java (it extends ClientBundle and holds references to images etc) in multiple classes and in each class I would create an instance of  it class using GWT.create(Resources.class) 
Would making this class a singleton offer me tangible performance gains or is it not worth the engineering effort ??  I am not looking for a quantified answer necessarily but even something of a gut check would suffice.


Chris McBrien

unread,
Jul 6, 2011, 11:39:18 PM7/6/11
to google-we...@googlegroups.com
I believe that GWT.create will by default give you back a shared single instance.

karthik reddy <karthik...@gmail.com> wrote:


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/WRE3Jx1rph0J.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Elhanan Maayan

unread,
Jul 7, 2011, 1:48:45 AM7/7/11
to google-we...@googlegroups.com
can i use it with my normal classes i'm looking for a way to have a singleton class and obtain it from a shared location, said class will contain, eventsbus,ActivityManager,ActivityMapper etc..

i also rely in many cases on static variable which are androgynous clases, i failed to to see that pressing F5 does not in fact re-initilzes them .

Thomas Broyer

unread,
Jul 7, 2011, 8:34:54 AM7/7/11
to google-we...@googlegroups.com
When you ask such questions to yourself, look at the generated classes (pass -gen to the DevMode or Compiler so it writes them to disk).

First, a GWT.create() always creates a new instance (it's equivalent to a 'new' with the zero-arg constructor of the replacement or generated class).

ClientBundles keep all their resources in static fields, so it really doesn't matter how many instances of the ClientBundle you have (don't worry, it'll be entirely, or almost entirely, optimized out by the compiler), and in other words, making it a singleton won't change anything (in terms of performance or whatever)
Reply all
Reply to author
Forward
0 new messages