[opencms-dev] Question about creation/reuse of template classes

Michael Schmitt mi.schmitt at gmx.de
Tue Jun 17 14:17:01 CEST 2003


Hi Thomas (and everyone else who reads this),
first of all, I would like to thank you giving me an answer to my question.
I just started to guess that noone else is able to see my messages
except me ;)

> "Michael Schmitt" <mi.schmitt at gmx.de> writes:
> > It would be nice if someone will, at least, tell my why my posts are
> > unaswered?
>
> Maybe noone had an answer. I don't know.
I thought that some of the developers of OpenCms participate at this
mailing list. So, even if none of the users had the same problems, at
least a developer should be able to explain the creation process of
Template classes.
By the way, do some UML sequence diagrams exist for some standard
OpenCms actions?

>
> > I wrote several template classes.
> > Some of them will be cached dependent on some parameters.
> > Others should never be cached.
> > The caching mechanism works as I expected (several variants
> > have been created dependent on different parameters).
> > But for the templates that should not be cached, I am uncertain
> > about the creation of new instances of my template class. It
> > seems to me as if a new instance is created for every call (every
> > web-call of a page that uses the corresponding template).
>
> Why does it seem so?
Well, the constructor is called for every call.

> I think if caching is disabled the template is
> being parsed for every request; so if you are creating Objects in your
> Class there will be new ones for every request.
>
> > But I would like to have that for every call the same instance will
> > be reused.
> > Is this somehow (cofiguration, programming) possible?
>
> http://www.fluffycat.com/java/JavaNotes-GoFSingleton.html
>
Sure, that will work and it is the way I do it now. But it does not
prevent OpenCms from creating new instances of the
Template-class. So, I have to delegate all the functionality from
Template-class to the singleton.
But what I need is not a real singleton, but something that
maintains the state for some Template-class - XML-Template
combination. For fullfilling that requirement I wrote some kind of
repository that stores a set of objects (that represent the state of
my Template-classes) which may be accessed by a key. As the key I use
a combination of the classname and the XML-Template path.
It works, but the same behaviour may be realized much more simple by
just having a way to reuse an instance of the Template-classes.


> > A second question (that is only relevant if no new instance will
> > be created for every call) is about thread-safety of the template
> > classes.
> > Does OpenCms ensures that only one thread accesses the
> > getContent() method of the template classes?
>
> I think there's no thread around there.
>
Oops, it seems as if my writing is really not very understandable.
I wrote about java threads (synchronization). If you mean the same,
I really do not understand your answer.

>
> I don't know if this did help you, so maybe you understand why you
> didn't get many answers. Or it was just me who can't give an exact
> answer. Anyway.

As I mentioned earlier: For now, I am happy that there is an answer at
all. And, so far, your answer strengthens my opinion that there will
be created a new instance for every call.

bye,
michael

>
> Best Regards,
> Thomas März
>
> _______________________________________________
> This mail is send to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://mail.opencms.org/mailman/listinfo/opencms-dev
>




More information about the opencms-dev mailing list