wood burning stoves 2.0*
The moose likes JSP and the fly likes Syncronization in JSP w/o isThreadSafe Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Syncronization in JSP w/o isThreadSafe" Watch "Syncronization in JSP w/o isThreadSafe" New topic
Author

Syncronization in JSP w/o isThreadSafe

ashirvad jain
Ranch Hand

Joined: Nov 09, 2006
Posts: 50
Acuatally we are developing an application in which,number of customer can connect to our application.
Sp we want that all the data means thread remain safe without using IsThreadSafe directive.
Coz want more assurance so we are thinking to make our method sync in that.
But bit confuse how can we do that w/o the help Of isThreadSafe.

Thanks in Advance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

If you follow good practices and don't put any Java scriplets in your JSPs, you will not need to worry.

If you do use scriptlets, be sure not to use the <%! %> construct.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
ashirvad jain
Ranch Hand

Joined: Nov 09, 2006
Posts: 50
hi Bear ,
Thanks so for the response.
Actaully you right ,we are using scriptlets <% %> and our actual code means, we have jdbc connectivity program in that <% %>.and we are accessing the user parameter from the Url and doing some authorization.
So we implemented our logic in that <% %>
So what do you think should we go for syncronized keyword with the actaul module or try some diff thing to get more accurate safety..means deadlock avoidance..
..
And according to reply if we make our scope global to service then it works fine..
ashirvad jain
Ranch Hand

Joined: Nov 09, 2006
Posts: 50
Bear
---------------------------------------------------------------------
If you follow good practices and don't put any Java scriplets in your JSPs, you will not need to worry.
---------------------------------------------------------------------

What do you mean by this?
Actually we are ready to learn and try new things on our application.
And we are not aware of such good practices that you mentioned Here.
So please guide us through some resourses or sample code anything ,
its really appriciatable.
And again thanks bear...
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you declare a variable within the <%! %> tags, it will become an instance variable.
Instance variables are common to all requests to your page and are therefore not threadsafe.

If you declare all of your variables within the <% %> tags, they will, in the generated servlet code, be written inside the service method. Since they will be local to the service method, they will be thread-safe.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
ashirvad jain
Ranch Hand

Joined: Nov 09, 2006
Posts: 50
HI ben thanks for providing the basic Knowledge of JSP like:

--------------------------------------------------------------------------
If you declare a variable within the <%! %> tags, it will become an instance variable.
Instance variables are common to all requests to your page and are therefore not threadsafe.

If you declare all of your variables within the <% %> tags, they will, in the generated servlet code, be written inside the service method. Since they will be local to the service method, they will be thread-safe.
---------------------------------------------------------------------------

But i thought that you gonna provide us some advance k/w of JSP ..
I know that, but i expect more advance solution, cuase we tried that n works fine.But stil we are not sure about the performance..
So i expect some more advance Tech through which we can get the assurance of Synchronization..with the performance.

If you require some more k/w about our application then i can give ..

Regards,
Ahirvad
 
Consider Paul's rocket mass heater.
 
subject: Syncronization in JSP w/o isThreadSafe