[Opensource] get java.util.ConcurrentModificationException

Himanshu Dattatraya Thube himanshu-t at lycos.com
Mon Nov 4 15:08:17 PST 2002


Hi 

I think this piece of text from JAVADOC's will help to solve your problem.

public class ConcurrentModificationException
This exception may be thrown by methods that have detected concurrent modification of an object when such modification is not permissible. 

For example, it is not generally permssible for one thread to modify a Collection while another thread is iterating over it. In general, the results of the iteration are undefined under these circumstances. Some Iterator implementations (including those of all the collection implementations provided by the JRE) may choose to throw this exception if this behavior is detected. Iterators that do this are known as fail-fast iterators, as they fail quickly and cleanly, rather that risking arbitrary, non-deterministic behavior at an undetermined time in the future. 

Note that this exception does not always indicate that an object has been concurrently modified by a different thread. If a single thread issues a sequence of method invocations that violates the contract of an object, the object may throw this exception. For example, if a thread modifies a collection directly while it is iterating over the collection with a fail-fast iterator, the iterator will thow this exception. 

Note that fail-fast behavior cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast operations throw ConcurrentModificationException on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness: ConcurrentModificationException should be used only to detect bugs. 


Cheers
---
Himanshu D Thube
Germany

On Mon, 04 Nov 2002 10:30:44  
 Philipp Reber wrote:
>Hi there,
>
>At the moment I'm working with expresso 4.02 and I'm having some problems:
>
>I have a TimestampDBObj which contains the workingtime of users. To output 
>this values in a table, I
>request the database with retrieving multiple records by each day and 
>project. All received users in the List
>I put out in the tabe, each one in a new row.
>
>The problem is: Retrieving multiple records from the DB (for loop) I get 
>sometimes a an
>Exception 2  java.util.ConcurrentModificationException. I did several tests 
>but the Exeptions
>occueres not regular. It just happens by coincidence. I checked the 
>setFields(), they are always correct.
>The mistake must be somewhere in the response of the DB. Unfortunately I 
>have now idea any more at
>the moment.
>
>Does anybody have or had similar Exceptions problems or is it just me how 
>is doing some garbage??
>
>I would be very happy to get some response.
>Thanks in advanced!
>
>Greetings, Philipp
>
>
>Some of my code:
>
>         /********************************************************************************
>         * Create blocks
>         ********************************************************************************/
>         // create a list block
>
>         Block blockList = new Block("ProjecttimeList");
>         myResponse.add( blockList );
>         blockList.setAttribute("table", "Y");
>
>         String head = " Day | Date | User | Activity | Time ";
>         blockList.setAttribute("header-row",head);
>
>         try{
>             // create a block for each row
>             Block blockRow = new Block("row");
>             blockRow.setAttribute("row", "Y");
>
>             // select each day of month
>             for (int p = 1; p <= 31; p++){
>               if (p < 10){
>                 selecteddate = selectedYear + selectedMonth + "0" + p;
>                 }
>               else{
>                 selecteddate = selectedYear + selectedMonth + p;
>                 }
>
>                 try{
>                   TimestampDBObj timestampsList = new TimestampDBObj();
>                   TimestampDBObj oneTimestamp = null;
>                   timestampsList.setField("ts_project", selectedProject);
>                   timestampsList.setField("ts_date", selecteddate);
>
>                   // retrieve records of specific date
>                   for (Iterator e = 
>timestampsList.searchAndRetrieveList("ts_date").iterator(); e.hasNext();){
>
>                     oneTimestamp = (TimestampDBObj) e.next();
>                     out2.println("p in for loop : " + p);
>
>                      // get day from date
>                      Weekday  myweekday = new Weekday();
>                      String weekday = 
>myweekday.getWeekday(Integer.parseInt(selectedYear), 
>Integer.parseInt(selectedMonth)-1, p);
>
>                      blockRow.add(new Output(weekday));
>                      blockRow.add(new 
>Output(oneTimestamp.getField("ts_date")));
>                      blockRow.add(new 
>Output(oneTimestamp.getField("ts_user")));
>                      blockRow.add(new 
>Output(oneTimestamp.getField("ts_activity")));
>
>                      oneSpanTime = 
>round(Double.parseDouble(oneTimestamp.getField("ts_span")), 2, 0);
>                      blockRow.add(new Output(Double.toString(oneSpanTime)));
>
>                      blockList.add(blockRow);
>
>                 }//end of for (row)
>
>                 }
>                 catch (Exception e){
>                   System.out.println("Exception 2 ;  " + e.toString());
>                 }
>
>              }//end of for from select each day
>
>
>         }//end of try (create each block for row)
>         catch (Exception de){
>         System.out.println("Exception 1 ;  " + de.toString());
>         }
>


__________________________________________________________
Outgrown your current e-mail service? Get 25MB Storage, POP3 Access,
Advanced Spam protection with LYCOS MAIL PLUS.
http://login.mail.lycos.com/brandPage.shtml?pageId=plus&ref=lmtplus



More information about the Opensource mailing list