Synchronized threads inside of a SERVLET

Discussion in 'Java' started by gfrommer@hotmail.com, Jan 24, 2005.

  1. Guest

    Hello everyone,

    I've written this very involved web application that allows users
    to create and pass around reports of various forms. In the main
    servlet, there exists two lists, activeReports and completedReports
    where I use to store the two types of reports. In a couple of places
    around the application, I need to move a report from the activeReports
    ArrayList into the completedReports HashMap. To make sure no one is
    iterating through either of the lists I used synchronized blocks like
    this:

    synchronized(completedReports) {
    synchronized(activeReports) {

    ArrayList al = (ArrayList)completedReports.get(rootTag);
    if(al == null) { al = new ArrayList(); }
    al.add(ReportObject);

    completedReports.put(rootTag, al);
    activeReports.remove(this);

    }
    }


    If a user executes this bit of code while another user is iterating
    through those lists, will there be problems?

    Do I synchronize on those lists when I add/remove or when im iterating
    through the lists. (Add/remove, because thats when its changing
    structure... yes?)

    Thanks everyone
     
    , Jan 24, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. circuit_breaker
    Replies:
    2
    Views:
    2,082
    Jack Jia
    Apr 4, 2004
  2. Jerry
    Replies:
    4
    Views:
    132,050
    tonni
    Aug 11, 2010
  3. Pep
    Replies:
    6
    Views:
    29,365
  4. dmcreyno
    Replies:
    9
    Views:
    9,623
    Mark Space
    Jun 27, 2006
  5. ankur
    Replies:
    4
    Views:
    1,510
    Eric Sosman
    Nov 28, 2008
Loading...

Share This Page