Win a copy of Spark in Action this week in the Open Source Projects forum!
  • 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Variables scope

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. I have some questions:
The local variables and method aruments are thread safe?
How I can use and how work the SingleThreadModel?
Is a god idea use the service method in a Servlet derivated from HttpServlet?
ThX for your help.
JcSO
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. yes, local variables are thread safe
2. you just declare that the servlet implements SingleThreadModel - the servlet engine does the rest automatically.
3. why would you want to? Inheriting from HttpServlet is done so you can use doPost, etc. People doing special processing of non-HTTP requests override service.
Bill
 
Julio Carlos
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ThX for your help William, i have another question:
In my actual application i have a socket connection and DB connection, but i open and close theses connections each time that i call my servlet, now i want use a pool for theses connections, which framework is recomended???
confused:
JcSO :
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did a search at java.sun.com for "connection pool" and found a bunch of references. I don't have any particular recommendation.
Bill
 
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can reuse at least database connection if you initialize them in the init() method of the servlet and destroy them in the destroy() method.
In another thread they said that apache.jarkarta.struts has a connction pool implemented. Why not use struts or trying to understand their connection pool implementation?
 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Julio Carlos??? hhmmm.. this really is a Latin Name. The first latin person I've seen around since I joined this great community... good to see new people around.
cheers
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have point to make , if local variable are referanceing some common object, i.e if two variable point to same object, than it may not be Thread safe
 
Axel Janssen
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by jawa lal:
I have point to make , if local variable are referanceing some common object, i.e if two variable point to same object, than it may not be Thread safe


Jawa,
there are no threading-problems with local variables in the service() method of servlets:
For every incoming doGet, doPost request the Servlet-Container spawns up a new thread.
 
    Bookmark Topic Watch Topic
  • New Topic