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 8276271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:19:26+00:00 2026-06-08T08:19:26+00:00

List<Ball> myObjs = myThreads[threadIndex].getMyObjList(); int initialSize = Collections.synchronizedList(myObjs).size(); Throws ConcurrentModificationException. I have also tried

  • 0
List<Ball> myObjs = myThreads[threadIndex].getMyObjList();
int initialSize = Collections.synchronizedList(myObjs).size();

Throws ConcurrentModificationException. I have also tried putting this in a
synchronized(myObjs) block, but it also didn’t work. What is the solution? Everywhere else where I use this list, it is in an synchronized(block).

P.S. This error also ends up producing BrokenBarrierException. (yes, I am using cyclic barrier for synchronization)

EDIT: Here is the stack trace:

Exception in thread "Thread-3" java.util.ConcurrentModificationException
at java.util.ArrayList$SubList.checkForComodification(ArrayList.java:1091)
at java.util.ArrayList$SubList.size(ArrayList.java:921)
at java.util.Collections$SynchronizedCollection.size(Collections.java:1573)
at Part2.Animation.processCollisions(MyClass.java:133) // This is the call to size()

EDIT: The loop looks like

for (int threadIndex=0; threadIndex < numThreads; threadIndex++) {
  List<Ball> myObjs = myThreads[threadIndex].getMyObjList();
  int initialSize = Collections.synchronizedList(myObjs).size();
}

And regardless of numThreads, the exception happens when threadIndex=1.

  • 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-06-08T08:19:27+00:00Added an answer on June 8, 2026 at 8:19 am

    Looking at the source code for some of the List classes, I can’t see how it is possible that calling size() will throw a ConcurrentModificationException. It would help if you showed us a stack trace.


    But in the meantime, you appear to have a fundamental misconception about what Collections.synchronizedList does. What it does is create and return a list wrapper that will ensure that operations on the same wrapper instance are synchronized.

    It does not in anyway prevent threads from performing unsynchronized operations on underlying list; i.e. the list object that you just wrapped. If a thread has the reference for the underlying list, it can access it directly without going thrpough the wrapper. And neither does it do anything to synchronize operations using different wrappers for the same underlying list. So if you call Collections.synchronizedList twice on the same list, you will create two distinct wrappers that do not synchronize with each other.

    So, in fact your Collections.synchronizedList(myObjs).size() does not perform any meaningful synchronization at all. No other thread can get hold of the synchronized list wrapper that is created, so no other thread can synchronize with this one via the wrapper.

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

Sidebar

Related Questions

I have this following test code: public static final String[] list = { apple,ball,cat,dog,egg,fan,girl,hat,igloo,jerk
List<int> megalist; int boxId; boxId = ListofUniqueIDSpecificToDate.IndexOf(lstbox.SelectedIndex);<< this is wrong I'm trying to display
list<int> foo; list<int> foo2; list<int>::iterator foo_end = foo.end(); list<int>::iterator foo2_end = foo2.end(); for (list<int>::iterator
I have the following List which contains the following collection. How i can transform
I have defined the following record: type Ball = { center : Vector3<m> radius
I have a list. The list can contain multiple items of the same enum
Folks, I have this array: var list = new Array('Archer','Archer','Banker','Lantern','Toryboy','The Barb','Tim Whiffler','Glencoe','Warrior','Nimblefoot','The Pearl','The Quack','Don
List<string> arguments = new List<string>(Environment.GetCommandLineArgs().Skip(1).Take(4)); int variant = consoleOptions.HandleInput(arguments); public int HandleInput(List<string> input) {
List<String> listStr = new ArrayList<String>(); if(listStr.size == 0){ } versus if(listStr.isEmpty()){ } In my
I have a list of strings with different numbers of words, eg. abc =

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.