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

  • Home
  • SEARCH
  • 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 6854081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:35:23+00:00 2026-05-27T01:35:23+00:00

I have the following (simplified) code periodically run by a Thread in the class

  • 0

I have the following (simplified) code periodically run by a Thread in the class A (once per second):

Socket s = new Socket(IP,PORT);
ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
synchronized(this) {
   oos.writeObject(this);   //Exception HERE
   oos.flush();
}
...

The object (this) to send through the socket has an object of the class B as instance variable and B has a LinkedList<Long> as instance variable.

The application throws ConcurrentModificationException:

E/AndroidRuntime(681): FATAL EXCEPTION: Thread-10
E/AndroidRuntime(681): java.util.ConcurrentModificationException
E/AndroidRuntime(681): at java.util.LinkedList$LinkIterator.next(LinkedList.java:124)
E/AndroidRuntime(681): at java.util.LinkedList.writeObject(LinkedList.java:973)
E/AndroidRuntime(681): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(681): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1219)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1575)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1143)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:413)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1241)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1575)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1143)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:413)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1241)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1575)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
E/AndroidRuntime(681): at java.util.LinkedList.writeObject(LinkedList.java:973)
E/AndroidRuntime(681): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(681): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1219)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1575)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1143)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:413)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1241)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1575)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689)
E/AndroidRuntime(681): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
E/AndroidRuntime(681): at qoe.Application.connectUpdate(Application.java:194)
E/AndroidRuntime(681): at qoe.Application.access$0(Application.java:183)
E/AndroidRuntime(681): at qoe.Application$AutoUpdate.run(Application.java:217)

I run this app in Android with Eclipse and AVD, Windows 7 x64. Thanks in advance.

Edit: After many tests I think that the method that could cause problem is the following:

/* Instance variables */
private LinkedList<Long> mylist;
private long value;
/* The incriminated method */
public synchronized void myBadMethod() {
   this.mylist.add(this.value);
}
  • 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-27T01:35:24+00:00Added an answer on May 27, 2026 at 1:35 am

    Solved in 2 step.

    1) I’ve used CopyOnWriteArrayList (a thread-safe variant of ArrayList). But in this way I had another issue: the operation remove by Iterator is not supported.

    2) To resolve this issue I referred to this question:

    LinkedList<Long> to_remove = new LinkedList<Long>();
        for(int i = 0; i < this.mylist.size(); i++) {
    
            Long current = this.mylist.get(i);
            if(conditionToRemove)
                to_remove.add(current);
        }
        this.mylist.removeAll(to_remove);
    

    The drawback is that this is an expensive operation.

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

Sidebar

Related Questions

I have the following code(simplified). public class OrderProcessor { public virtual string PlaceOrder(string test)
Consider the following simplified version of my code. I have a template class A
I have the following C++ code (simplified version): class Shape { bool isCircle =
I have the following (simplified) code: IDbConnection connection = new SQLiteConnection(GetConnectionString()); if (connection.State ==
If I have the following code (simplified version of the problem): class TestA {
Imagine I have the following code (simplified regarding my real context of course): <div
I'm using gcc 4.3.2. I have the following code (simplified): #include <cstdlib> template<int SIZE>
I am debugging some code and have encountered the following SQL query (simplified version):
I have following situation (simplified, of course): MyDomain.groovy: class MyDomain { MyAnotherDomain anotherDomain //
I am using the SQLite database and have the following persistent class (simplified): public

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.