Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5969283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:12:29+00:00 2026-05-22T20:12:29+00:00

I have a general question regarding synchronized List. Lets say that in the constructor

  • 0

I have a general question regarding synchronized List.
Lets say that in the constructor I am createing a list

List synchronizedList = Collections.synchronizedList(list);

and I have one method adds an object to the list.

public void add(String s){ 
    synchronizedList.add(s)
}

There is another thread that checks every few seconds if there are a few rows , dump it to a file and deletes them all.

Now lets say I iterate each row and save it to the db.
after all iteration I clear the list.

How does the multithread support help me?
I could add an element to the list just before the clear() in the other thread occurs .
Unless I manage the lock myself (which I dont realy need a synched list for that ) it myself.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:12:30+00:00Added an answer on May 22, 2026 at 8:12 pm

    The synchronized list returned by Collections won’t help in your case. It’s only good if you need to guarantee serial access to individual method calls. If you need to synchronize around a larger set of operations, then you need to manually wrap that code in a synchronized block. The Javadoc states:

    It is imperative that the user manually synchronize on the returned list when iterating over it.

    If your list is used elsewhere you can at least safeguard it from individual method calls that would otherwise not be thread-safe. If you’re entirely managing the list however, you can just add a synchronized block to your add method and use the same lock that you’ll use when iterating over it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple, general question regarding a real small issue that bothers me:
A general architecture question in Sitecore 6... Let’s say we have a situation where
I have general question regarding the use of pointers vs. references in this particular
I have a general question regarding UITableViews. here is my situation. I have a
I have a relatively general question regarding SAX. I understand how it works, and
I have some question regarding database performance in general. I'm using Sqlite but I
I have a question regarding an ArrayList of Integers, or primitive types in general.
I have a general question regarding Android's separation of layouts into layout.xml files: My
All, I have a very general question regarding a future project. I need to
Ok another WPF question, well I guess this is just general .NET. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.