Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

please help on my doubts.. ;-)  RSS feed

 
Jack Daniel
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi e'body..
Well, i have 2 questions, which confuse me, whether i am doing anything wrong or not...
first one:
(1) In all my servlets,.. and in the init() method.. I actually do the JNDI lookup to retreive the Data source object.. infact in all my servlets init() method.. is that OK?? or is it something bad as far as performance would go.. and any other solution to this, please let me know..
something like: in the init() method for all servlets:

another question I have is regarding the memeber variables of the servlet(s).. They would be shared by all the Threads.. so might land me in trouble.. right?
BUT what i am doing is i am declaring these references as member variables.. does this land me in problems..??

These are the only references I declare as member variables in all my servlets.. Am I doing something wrong?? or is it ok..
I will be so happy if anybody can help me solve my confusion and explain, if i am doing something wrong.. or is it OK..??
It'll be GREAT, if anybody can help me
waiting for your reply(s)
cheers
 
R K Singh
Ranch Hand
Posts: 5390
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by prashant Kakani:
These are the only references I declare as member variables in all my servlets.. Am I doing something wrong?? or is it ok..

Member variable are vulnerable to data corruption.
Even though they are reference but they will be shared among all threads ..
So its better to make them local variable.
and if you ned it across methods then pass it as argument.
HTH
 
Jack Daniel
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Member variable are vulnerable to data corruption.
Even though they are reference but they will be shared among all threads ..
So its better to make them local variable.
and if you ned it across methods then pass it as argument.

Thanks a lot dude,.. i think i'll somehow make changes and make sure that I don't have any member variables..
And what about the Data Source JNDI lookup thing in the init() method.. hav any idea??
One more similar doubt i was getting..!!
IN any JSP, if I declare anything like..
<%!
String TimeDifference=null;
double itr1,itr2,itr3,itr4,totalTime;
%>
these would infact become memeber variables, in the generated servlet right..??? which would definitely put me in Trouble.. please help me on this..
I am really happy that I am learning about these things,..
cheers
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!