I had this 'private' session with nic, but maybe someone else has thougts
about this??

-----Original Message-----
From: Joost Verhagen
Sent: vrijdag 21 juli 2000 9:23
To: 'Nic Ferrier'
Subject: RE: RE: Cloning or File-IO in my servlet?


Hi Nic,

I think know what you mean but maybe I don't understand you completely.
Suppose we have the following servlet:

class surfer extends httpServlet {
  private XmlDocument doc;
  init() {
    // read html file and parse it into xml-dom
    InputSource input = Resolver.createInputSource(new
File(myTemplateFileString));
    doc = XmlDocument.createXmlDocument(input,false);
  }

  doGet(req, res) {
    // set the various nodes of the xml-object depending on
    // req-parameters and return it on the outputstream
    // for example:
    doc.findNode("OPTIONLIST).append(myOptionlist);
    res.getOutPutWiter().print(doc.getHTML());
  }
}

If i have a lot of requests handled by the servlet, for correct result the
requests have to be handled sequentially (they must wait until the
dom-object manipulation of the previous manipulation is finished): I have
only 1 dom object in memory so setting the values parralel would result in
incorrect results.
The option would be to let the servlet implement the singleThreadModel, but
i do not want to do this (this would result in 1 servlet for every request,
which is more expensive then the alternatives, in my opinion).

So i thought the only way to give every request it's own xml-object without
reading a file each time is to clone the xml-object we created at init-time.
When talking to you i realized i can read the template to an in-memory
object (String or something) which i can parse and return for every request.
But then i still have to parse or copy (or something) it into a new
xml-object each time.

Even with what you tell me here, i have the multi-threading problem, or am i
wrong? Were your servlets implementing the singlethreadmodel or were they
multi threading? Were did you create your xml-object and how did you return
it to a request?

If you have a solution around this problem, i would love to hear it.

Tanx a lot for your efforts so far.

Joost

> -----Original Message-----
> From: Nic Ferrier [mailto:[EMAIL PROTECTED]]
> Sent: donderdag 20 juli 2000 5:33
> To: [EMAIL PROTECTED]
> Subject: Re: RE: Cloning or File-IO in my servlet?
>
>
> >>> Joost Verhagen <[EMAIL PROTECTED]> 20-Jul-00 4:27:31 PM >>>
>
> >Please ignore my latest email sent to the servlet-interest
> >group. It finally struck me: i can read the template in an
> >io-object and parse it every time i need the xml-object.
> >This way i dont have to clone and don't have more then
> >one file-i/o.
>
> Hmmm... I *think* you've understood what I was saying.
>
> I'm not sure what you mean by "io-object" though.
>
> And you don't have to parse it every time either (unless you have a
> very complex requirement).
>
> What I was talking about was creating an in-memory representation of
> the XML document (which you do only once). Every time you need to
> output the document you simply format the in-memory representation to
> a Writer.
>
> The in-memory representation would most likely be some sort of tree
> like structure (but needn't be). "formatting" would probably involve
> having each node in the tree being able to output itself to a writer.
>
> A node that was to be computed might be created with some extra
> references to allow it to compute the data itself and output it when
> you called it's "format" method.
>
>
> In fact there are some very simple/elegant things you can do with
> this: I've used the same technique with HTML files in some very simple
> array based structures (not tress at all).
>
>
> If you dind't understand before I hope you will now.
>
>
> Nic
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to