The Artima Developer Community
Sponsored Link

Legacy Design Forum
Thread Safety



This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Thread safe string array

Posted by Shane Bailey on September 13, 1999 at 11:35 AM

If anyone is still monitoring the forum I am curious about
some things.
Previously, I made a class like this:

//Abbreviated to make things short...
class whatever extends HTTPServlet
static String[] file_template = null;

public init(){ //code here to read in template }

public void doGet(..., HttpResponse response)
String what_to_do_flag = getParameter("WHAT_TO_DO");
Vector return_page_vector = new Vector();
for(int i=0;i return_page_vector.addElement(file_template[i]);
UTIL.sendPage(return_page_vector, response);
public void reReadNewTemplateFromDisk(){ ... }

Now I would like to make it thread safe. At first it seems
really easy but a couple things are puzzling me. (1)The way I
have it now can I have a million doGet()s called without corrupting the array (i.e. just reading different parts of the
string array at the same time is my main concern)? (2) If I synchronize just for the very infrequent reReadNewTemplateFromDisk() call to be thread safe
then multiple reads which occur very often would then be set
to wait just for other reads to occur. And this will slow things down a lot.

Any way around this problem?


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us