Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

vector and servlet question...  RSS feed

 
Tobias Koch
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi cowboys n -girls!
Is it possible that I create a vector object in a servlet that still remains when the servlet lifecycle has ended? And can I access it from different servlets??
I think its not that complicated but I don't have that many practise yet :-(
Thx
Tobi
 
Michael Bronshteyn
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can make it static so it is available for the lifetime of the servlet class, and not for an instance of the servlet object. If you make it public, other servlets ( and all the other java classes so to speak ) will be able to access it.
[ July 01, 2003: Message edited by: Michael Bronshteyn ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For per-user persistance, you can stuff your Vector (recommend ArrayList instead) on the session. If it's to be app-persistant, the servlet context (aka application context) is the place to tuck it away.
I'd shy away from a static variable implementation.
hth,
bear
[ July 01, 2003: Message edited by: Bear Bibeault ]
 
Tobias Koch
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answers guys!
Why exactly is an ArrayList better than a Vector?
Because it is easier to access?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See my Collections Crib Sheet for some comparisons of collections. Sun tries to push us to the new Collections, away from Vector and Hashtable.
BTW: Be very careful about synchronization on any member variables, static or not. There can be many threads runing the same servlet at any time.
[ July 02, 2003: Message edited by: Stan James ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!