Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-10-2007, 05:47 PM
Member
 
Join Date: Nov 2007
Posts: 2
reddzer is on a distinguished road
is synchronization on method passing local variables as parameters needed
i have the following code

Code:
public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException { res.setContentType ("text/html"); PrintWriter out = res.getWriter(); //check to see if the session cookie has been created and that user has been fully authenticated //if the cookie doesnt exist they have just logged in and must be forwarded to cookieAuthentication //or the user doesnt have cookies enabled //no need to synchronize because local variables being used Cookie[] cookies = req.getCookies(); String user = req.getRemoteUser(); boolean authenticated = checkCookie(out, cookies, user); if (authenticated == true) //user authenticated continue { //create html welcome page createWelcome(out, user); } else { res.sendRedirect("login"); //cookie not created, send to login servlet (cookieAuthentication.java) } } private boolean checkCookie(PrintWriter out, Cookie[] cookies, String user) { boolean val = false; if (cookies!=null) //if cookies retrieved check them { for (int i=0; i<cookies.length; i++) { if (cookies[i].getName().equals(user)) { //if cookie name is the same as logged in user //then cookie has been created, return true val = true; } } } return val; }
i was wondering do i need to add synchronization to checkCookie() when i call it to keep "cookies" and "user" thread safe when passing them the method or are they ok because they are local variables not instance variables.
i.e in the doGet change

Code:
boolean authenticated = checkCookie(out, cookies, user);
to

Code:
synchronized (this) { boolean authenticated = checkCookie(out, cookies, user); }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Passing parameters in Eclipse DonCash Eclipse 2 04-08-2008 05:46 PM
[SOLVED] Why import isnt needed whn ref is used without storing to local variable N_i_X Advanced Java 2 03-31-2008 06:11 AM
JNI - passing and returning parameters by value java_to_c New To Java 0 01-31-2008 09:49 PM
Local Variables for a static method - thread safe? mikeg1z Advanced Java 1 11-16-2007 02:06 AM
Are Local variables thread safe ? samson Threads and Synchronization 3 08-09-2007 07:59 PM


All times are GMT +3. The time now is 04:36 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org