Jasypt Users Forum

Performance of StandardPBEByteEncryptor using Spring

by Mike Rowehl :: Rate this Message:

Reply to Author | View in Thread

Hey folks, I tried searching for this, but haven't found anything yet (sorry if it's there and I'm just looking for the wrong stuff).  I have a project that's using the Hibernate initialization using Spring to provide the encryptor, as described here:

http://jasypt.org/hibernate3.html

The code is working, encryption and decryption performed, peachy.  However, when I have the system running within Tomcat I see very slow response times when there are multiple requests hitting encrypted columns.  If I do a thread dump when things are performing poorly I see a number of threads all waiting for the same decryptor object.  Thead dump excerpt:

"http-5801-25" daemon prio=10 tid=0x0000000045ba2400 nid=0x2abd waiting for monitor entry [0x00000000461dd000..0x00000000461dfb10]
   java.lang.Thread.State: BLOCKED (on object monitor)
        at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.decrypt(StandardPBEByteEncryptor.java:784)
        - waiting to lock <0x00002aaab33e0270> (a javax.crypto.Cipher)
        at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:639)
        at org.jasypt.hibernate.type.AbstractEncryptedAsStringType.nullSafeGet(AbstractEncryptedAsStringType.java:143)
        at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:105)
        at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
        at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2096)
        at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1380)
        at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1308)

Many of the threads are waiting on exactly the same object it looks like.  I'm an admitted Spring/Hibernate/Tomcat noob, but I'm assuming what's happening is that the encryptor being used by Hibernate is a singleton cause of the way Spring initializes it, and all the Tomcat threads are all jammed up waiting for the same object.

Am I misinterpreting what's going on, or does this seem likely?  And if so, is there a different way to configure these objects so that I can avoid contention on a shared resource?  Thanks,

- Mike