5 Replies Latest reply: Jan 3, 2010 1:59 PM by Greybird-Oracle RSS

    save an object including CopyOnWriteArrayList attribute

    742171
      In order to increase thread-safety, I have replaced an ArrayList by a CopyOnWriteArrayList as an attribute of a class.

      The issue is that now Berkeley DB JE (4.0.17) does not work with that object.
      Just creating an index is now rejected:
      java.lang.IllegalArgumentException: Class could not be loaded or is not persistent: java.util.concurrent.CopyOnWriteArrayList'

      Do you know it there is a mean to use CopyOnWriteArrayList with Berkeley DB?
        • 1. Re: save an object including CopyOnWriteArrayList attribute
          Greybird-Oracle
          Hi,

          To answer your question we need a little more information. If you created a PersistentProxy for CopyOnWriteArrayList and you registered it properly, then it should work in JE 3.3 and 4.0. Perhaps there is something you were doing wrong, but it just happened to work in 3.3, and it no longer works in 4.0.

          Could you please post the details on what your proxy class looks like and how you are registering it?

          Thanks,
          --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
          • 2. Re: save an object including CopyOnWriteArrayList attribute
            742171
            In fact I have not created a proxy class.

            In the object I want to save with BerkeleyDB, I used to have that attribute "ArrayList<String> myList = new ArrayList<String>(); "
            Save was ok.

            The issue came when I replaced ArrayList by CopyOnWriteArrayList, said everywhere to be equivalent but thread-safe.
            "CopyOnWriteArrayList<String> myList = new CopyOnWriteArrayList<String>(); "
            does not work

            It seems that that class is nor really equivalent.
            What shall I do?
            • 3. Re: save an object including CopyOnWriteArrayList attribute
              Greybird-Oracle
              Please see the javadoc for PersistentProxy. You will need to create one. There is a built in proxy for ArrayList, but not for the class you're using.

              I'm curious about why you need thread safety. In general, persistent objects are only used by one thread at a time.

              --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
              • 4. Re: save an object including CopyOnWriteArrayList attribute
                742171
                I will read the proxy doc.

                My software has a graph of objects with mutual invocations.
                The ArrayList is for the identifiers of the connected nodes.

                Nodes are to be made persistent.

                Several threads invoke nodes, which themselves invoke nodes etc. so I have the problem of making that thread-safe.
                • 5. Re: save an object including CopyOnWriteArrayList attribute
                  Greybird-Oracle
                  In addition to looking at the PersistentProxy javadoc, I strongly suggest looking at the source code for the built-in collection proxy objects:

                  src/com/sleepycat/persist/impl/CollectionProxy.java

                  This includes the implementation of the proxy for ArrayList.

                  --mark