• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

1) Request Attributes? 2) SessionListener?

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have made a web-based application using JSP & servlets.

1) Query
Whenever my application is interacting the database for getting ResultsSet i am setting the request attribute as

request.setAttribute("ROWSFOUND","NO"); if no rows are found
else
request.setAttribute("ROWSFOUND","YES"); if rows are found

So what i would like know is that everytime a object would get created for attribute 'ROWSFOUND' or the same object values will be REPLACED for this attribute??

Because if everytime the object for attribute 'ROWSFOUND' would get created then it will take a lot of memory because i m not removing this request attribute.So if this is the thing what should i do?? And i dont want to remove this manually because if i would do that i will have to write a removeAttribute() statement in my each class which is interacting with the database & i have a lot of classes.


2) QueryI want to write a SessionListener class for this application which can automatically remove the session attribute's objects created after a particular time. So how to do this??


Thanks,
Jignesh
[ March 21, 2006: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So what i would like know is that everytime a object would get created for attribute 'ROWSFOUND' or the same object values will be REPLACED for this attribute??




the same object values will be REPLACED
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


So what i would like know is that everytime a object would get created for attribute 'ROWSFOUND' or the same object values will be REPLACED for this attribute??



You should think of a Map while thinking of Request. So just like Map can't have duplicate keys Request too.

So the old object will be replaced by the new one.
 
Jignesh Gohel
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply,

So what about the memory occupied by the request attribute object.
You said it would get replaced so,if i am not mistaken, no extra memory would be wasted right??

Kindly sort out my second query also??

Thanks,
Jignesh
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, the old string would be set free for garbage collection.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wouldn't a Boolean true or false be a better choice than the strings "YES" and "NO"?
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but Bear, the attributes are set in the request. and boolean true and false wont be permitted as they are primitives.right??
 
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Geetu,
Use Wrapper then.....if you are using JSE 5.0 then autoboxing will do the job

Shrinivas
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by geetu lalchandani:
but Bear, the attributes are set in the request. and boolean true and false wont be permitted as they are primitives.right??



I said Boolean, not boolean. I'd use the values Boolean.TRUE and Boolean.FALSE.
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Boolean will still be a object right..
how does it make a difference to use Boolean or String(performance wise).
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by geetu lalchandani:
Boolean will still be a object right..
how does it make a difference to use Boolean or String(performance wise).



Using Boolean will be more efficient because you won't have to do String comparisons... BUT that's a minor consideration. You should choose to use Boolean because it makes more sense than using strings with "YES" and "NO' or "TRUE" and "FALSE".
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic