Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-04-2010, 01:39 AM   PM User | #1
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
destruct inside construct

since I call this from many pages, not knowing if
session object called "sessionObject" already exists, I do each time:

Code:
SessionObject sessionObject= new SessionObject(request);
Code:
package mc.session.objects;

public class sessionObject
{
  ....  
  public sessionObject(HttpServletRequest req) throws Throwable
  {
      HttpSession session = req.getSession(true);
      if (session.getAttribute("sessionObject") != null)
      {
        // destruct this object as one instance of it, and only one 
        // that I need is already created
        super.finalize();
      }
  }
Anything that I don't see here ?

Hope this "sessionObject" gets collected by gc
at the time session ends.
BubikolRamios is offline   Reply With Quote
Old 01-04-2010, 08:35 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,162
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I wouldn't do it this way, at all.

I'd use a singleton. That is, a class where only one instance of it *can* be created.

Look up "singleton pattern" in the docs.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:10 PM.


Advertisement
Log in to turn off these ads.