db4o Developer Community

db4o open source object database, native to Java and .NET
Welcome to db4o Developer Community Sign in | Join
in Search
More Search Options

How to: java.util.concurrent.locks.ReadWriteLock in persisted object?

Last post 07-18-2008, 11:15 AM by Shake. 3 replies.
Sort Posts: Previous Next
  •  07-15-2008, 09:41 AM 50141

    How to: java.util.concurrent.locks.ReadWriteLock in persisted object?

    Hi,

    some of my business objects have a lock declared:

    private final ReadWriteLock lock = new ReentrantReadWriteLock();

     

    When I load such an object, "lock" is set to null which results in some nasty NPEs. Could anyone give me a hint how I should solve this problem?

     

     

    Thanks

    Johannes


     

  •  07-15-2008, 09:46 AM 50142 in reply to 50141

    Re: How to: java.util.concurrent.locks.ReadWriteLock in persisted object?

    Uups - intepreted something wrong: The lock is set, when the object has been loaded.

    But when I check the object within a Predicate, the lock is set to "null" (resulting in NPEs when I call a getter).

  •  07-18-2008, 09:18 AM 50204 in reply to 50142

    Re: How to: java.util.concurrent.locks.ReadWriteLock in persisted object?

    Please try:

    private final transient ReadWriteLock lock = new ReentrantReadWriteLock();
  •  07-18-2008, 11:15 AM 50207 in reply to 50204

    Re: How to: java.util.concurrent.locks.ReadWriteLock in persisted object?

    Yes, of course setting the lock "transient" works as expected. But then I have to initialize the lock lazily (using a method). How could I ensure the lock is set after an object has been loaded from the database? Forcing the usage of a constructor?
View as RSS news feed in XML