Hemant's right, that performance is often dependent on many things,... but
doing "new Boolean" is guaranteed to be slower.
If you look at the source of java.lang.Boolean, you'll see that the your
version of the code is identical to what Boolean itself does: therefore,
using Boolean is no win (and is a possible loss, since it's an extra method
call).
But anytime you create an object (like "new Boolean"), that will _always_
slow you down on creation, on garbage collection, and possibly on memory
fragmentation.
If you really want to use Boolean instead of a string literal, you can
mitigate the problem by using Boolean's static methods, and not creating a
Boolean. For instance, replace,
new Boolean("true")
with
Boolean.TRUE
and
new Boolean(String).booleanValue()
with
Boolean.getBoolean(String)
But using a string literal is no bad thing: since literals are intern()'ed
(see the javadoc for java.lang.String.intern()), more copies of the same
literal take no extra memory. Even better, you can use simple equality
("==") instead of Object.equals() to compare them. So, you can do something
like,
JSP1:
<% request.setAttribute("FLAG", "true"); %>
<jsp:include page="JSP2.jsp" flush="true"/>
JSP2:
<% if (request.getAttribute("FLAG") == "true")
{
/* ... */
}
%>
(At a guess, setAttribute()/getAttribute() is going to be faster than
getParameter(), just because you avoid parsing the request string, but it's
worth comparing the two.)
-- Bill K.
> -----Original Message-----
> From: Hemant Singh [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, June 03, 2001 1:45 PM
> To: [EMAIL PROTECTED]
> Subject: Re: get/setAttribute and getParameter...
>
>
> HI Zinger:
> answer to this question depends on env conditions
> setAttribute method stores the attribute in JVM itself for
> every session,
> while set parameter will pass the attribute as a header
> information to you
> new jsp.
> So it all depends on memory available, cpu speed, and no of
> pages you are
> going to use this technique.
> Cheers
> Hemant
> ----- Original Message -----
> From: "Oskar Zinger" <[EMAIL PROTECTED]>
> To: "TomcatDev" <[EMAIL PROTECTED]>;
> <[EMAIL PROTECTED]>
> Sent: Sunday, June 03, 2001 12:15 AM
> Subject: get/setAttribute and getParameter...
>
>
> > Hi,
> > What is more time consuming?
> >
> > JSP1:
> > <% request.setAttribute("FLAG", new Boolean("true")); %>
> > <jsp:include page="JSP2.jsp" flush="true"/>
> >
> > JSP2:
> > <% boolean FLAG = ((Boolean)
> > request.getAttribute("FLAG")).booleanValue();
> > if (FLAG) {
> > ..........
> > ...........
> > }
> > %>
> >
> > OR?:
> >
> > JSP1:
> > <jsp:include page="JSP2.jsp?FLAG=true" flush="true"/>
> >
> > JSP2:
> > <% String FLAG = request.getParameter("FLAG");
> > if (FLAG.equals('true")) {
> > ..........
> > ..........
> > }
> > %>
> >
> > OR?:
> >
> > JSP1:
> > <jsp:include page="JSP2.jsp?FLAG=true" flush="true"/>
> >
> > JSP2:
> > <% boolean FLAG = (new
> > Boolean(request.getParameter("FLAG"))).booleanValue();
> > if (FLAG) {
> > ..........
> > ..........
> > }
> > %>
> >
> >
> > AND, which way is it best practiced.
> >
> > Thankss for any help!
> > --
> > Oskar Zinger
>