• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

DataPool

 
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not sure how much information y'all can give me here, but i have a question about a nitpick.
i created a new DataPool() object in my "mystery" file for Servlets 4b... but the nitpick said:
"what instance methods are you using in your DataPool object?"
it seems obvious to me that i am using "put()" and "get()"... do i need a pool object?
 
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is easy to make the DataPool portion of this assignment too hard. From your post I think you may be headed in that direction.
The javadoc for DataPool shows two static methods that are very useful. You might have an epiphany.
 
Greg Harris
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i love the cryptic replies on this forum! are you talking about the 2 methods i mentioned above?
i have a weekend to spend programming, so i think i will get this one finished (for another round of nitpicking).
[ April 11, 2002: Message edited by: Greg Harris ]
 
Michael Pearson
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The cryptic replies are propagated by:
  • the Java Ranch community that is built on teaching not showing
  • the fear of a being reprimanded by a Sheriff or a Bartender



  • You referred to methods that provide the functionality "put" and "get". I must say I see two static methods that do that.
    I was hoping to encourage some analysis of why you are creating a new DataPool().
    [ April 11, 2002: Message edited by: Michael Pearson ]
     
    Michael Pearson
    Ranch Hand
    Posts: 351
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I am breathing easier, refer to this thread to read Marilyn's suggestions...
    DataPool
    [ April 11, 2002: Message edited by: Michael Pearson ]
     
    Chicken Farmer ()
    Posts: 1932
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Do you understand what the static keyword does? Not trying to belittle, just want to make sure that first you have a good understanding of that.
    If you do have a grasp of static methods, then it should be pretty obvious from reading the class definition why you don't need an instance of DataPool. Theoretically you could make an instance, but why mess with the overhead of creating an object when one isn't necessary?
     
    Michael Pearson
    Ranch Hand
    Posts: 351
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    it must be nice to have spurs, , and not worry about saying to much
     
    whippersnapper
    Posts: 1843
    5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Not to confuse the matter, but an instance of DataPool *does* get created (in the static initialization block) whenever you first access DataPool -- but as far as I can tell its purpose is just to get a new thread running.
    Always wondered if there's any reason Paul didn't give DataPool a private (or protected) constructor.
    (Unless he did it that way to trip up Cattle Drivers who go and create their own instances of DataPool!)
    Incidentally, I think being able to access a static method through an object reference is the second ugliest thing about Java.
     
    Michael Pearson
    Ranch Hand
    Posts: 351
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I did not want to go into DataPool's static initializer to avoid discussing Threads. Your point is correct and I appreciate the attention to detail.
    [ April 11, 2002: Message edited by: Michael Pearson ]
     
    jason adam
    Chicken Farmer ()
    Posts: 1932
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Originally posted by Michael Matola:

    Incidentally, I think being able to access a static method through an object reference is the second ugliest thing about Java.


    Agreed, and it is something I see many people who are new to the language doing. Been tutoring some people in my Java classes, and they never fail to mark all their methods static for some reason, but then go and create an object to start accessing the methods.
    And yes, it does create an object and starts a thread, which goes through and cleans up any tokens that have expired. Agreed, given the implementation of it, a private no-argument constructor would have made a lot of sense.
     
    Greg Harris
    Ranch Hand
    Posts: 1012
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    wow, thanks for all the replies! this has been very informative (it seems all the discussions between you three (and a few others) are informative).
    ( as greg slaps himslef in the forehead and thinks... now why didn't i think of that?"... )
    i have been in class the last 5 hours so i could not keep up with the discussion... so thanks for keeping it going.
    michael p.
    thanks for the link... i looked at the date and that was posted after i had looked at the DataPool code and written my first attempt. i guess i should have tried again.
    jason
    belittle me all you want... obviously i need to read up on "static" i just implemented DataPool like anything else and it worked... so i did not pay attention to what was really going on.
    michael m.
    thanks for pitching in and helping with my education... i am feeling really stupid for not thinking about what i was doing.
    [ April 11, 2002: Message edited by: Greg Harris ]
     
    Sheriff
    Posts: 9099
    12
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Originally posted by Greg Harris:
    belittle me all you want... obviously i need to read up on "static" i just implemented DataPool like anything else and it worked... so i did not pay attention to what was really going on.


    You implemented DataPool?
     
    Greg Harris
    Ranch Hand
    Posts: 1012
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    sorry, Marilyn... bad choice of words. read "implemented" as "used." i have been out of the Navy for 4 years, but i still use the terms.
     
    Trailboss
    Posts: 23192
    IntelliJ IDE Firefox Browser Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Originally posted by Michael Matola:
    Always wondered if there's any reason Paul didn't give DataPool a private (or protected) constructor.


    That's a good idea!
    I put it into my copy just now. When Marilyn gets her computer running again, she and I need to merge some stuff ... Then the change should be available.
     
    Michael Pearson
    Ranch Hand
    Posts: 351
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Looks like Michael M. deserves a gold star.
     
    Acetylsalicylic acid is aspirin. This could be handy too:
    Devious Experiments for a Truly Passive Greenhouse!
    https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
      Bookmark Topic Watch Topic
    • New Topic