AFAIK Object does not  implement Serializable

is there an object your code can implement for lock object that implements 
Serializable?

m-

________________________________
From: Burton Rhodes <burtonrho...@gmail.com>
Sent: Monday, January 25, 2021 1:52 PM
To: Struts Users Mailing List <user@struts.apache.org>
Subject: Re: NPE using OpenSessionBackgroundProcess class

The complete class is below (and also here: https://pastebin.com/Z8QyTRzM).
It extends org.apache.struts2.interceptor.BackgroundProcess which
implements serializable.  Do I need to explicitly implement?  Or do you see
anything else that might be the cause?  Many thanks.

package com.afs.web.common.struts.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import org.apache.struts2.interceptor.BackgroundProcess;
import org.springframework.orm.jpa.EntityManagerFactoryUtils;
import org.springframework.orm.jpa.EntityManagerHolder;
import
org.springframework.transaction.support.TransactionSynchronizationManager;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

/**
 * Used in conjunction with {@link OpenSessionExecuteAndWaitInterceptor}
 */
public class OpenSessionBackgroundProcess extends BackgroundProcess {

EntityManagerFactory entityManagerFactory;
protected boolean initializationComplete;
private Object lock = new Object(); // used for synchronization

public OpenSessionBackgroundProcess(String name, ActionInvocation
invocation, int threadPriority, EntityManagerFactory entityManagerFactory) {
super(name, invocation, threadPriority);
this.entityManagerFactory = entityManagerFactory;
initializationComplete = true;
synchronized (lock) {
lock.notify();
}
}

protected void beforeInvocation() throws Exception {
while (!initializationComplete) {
try {
synchronized (lock) {
lock.wait(100);
}
} catch (InterruptedException e) {
// behavior ignores cause of re-awakening.
}
}
EntityManager em = entityManagerFactory.createEntityManager();
TransactionSynchronizationManager.bindResource(entityManagerFactory, new
EntityManagerHolder(em));
super.beforeInvocation();
}

protected void afterInvocation() throws Exception {
super.afterInvocation();
EntityManagerHolder emHolder = (EntityManagerHolder)
TransactionSynchronizationManager.unbindResource(entityManagerFactory);
EntityManagerFactoryUtils.closeEntityManager(emHolder.getEntityManager());
}
}

On Fri, Jan 22, 2021 at 2:44 AM Lukasz Lenart <lukaszlen...@apache.org>
wrote:

> czw., 21 sty 2021 o 18:56 Burton Rhodes <burtonrho...@gmail.com>
> napisał(a):
> >             synchronized (lock) {   <-- **** NPE is here ****
>
> How is this lock defined? Is it a serializable class?
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>

Reply via email to