I used ExecuAndWait in ExecuAndWait
I get an NPE error when setting an attribute in a request in action (which takes a long time)
Here is the stack track:
java.lang.NullPointerException at org.apache.catalina.connector.Request.notifyAttributeAssigned(Request.java:1563) at org.apache.catalina.connector.Request.setAttribute(Request.java:1554) at org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.java:542) at javax.servlet.ServletRequestWrapper.setAttribute(ServletRequestWrapper.java:239) at com.os.gfnactions.SiteAction.createSite(SiteAction.java:1298) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:450) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:289) at com.os.interceptor.BackgroundProcess$1.run(BackgroundProcess.java:60) at java.lang.Thread.run(Unknown Source)
Source snipate:
Action class:
public String createSite() throws Exception { ---- HttpServletRequest request = ServletActionContext.getRequest(); request.setAttribute("test", "test"); {At this line I got error} --- }
From ExecuteAndWaitInterceptor.java
231 if ((!executeAfterValidationPass || secondTime) && bp == null) { 232 bp = getNewBackgroundProcess(name, actionInvocation, threadPriority); 233 session.put(KEY + name, bp); 234 performInitialDelay(bp); // first time let some time pass before showing wait page 235 secondTime = false; 236 }
From BackgroundProcess.java
public More ...BackgroundProcess(String threadName, final ActionInvocation invocation, int threadPriority) { 50 this.invocation = invocation; 51 this.action = invocation.getAction(); 52 try { 53 final Thread t = new Thread(new Runnable() { 54 public void More ...run() { 55 try { 56 beforeInvocation(); 57 result = invocation.invokeActionOnly(); 58 afterInvocation(); 59 } catch (Exception e) { 60 exception = e; 61 } 62 63 done = true; 64 } 65 }); 66 t.setName(threadName); 67 t.setPriority(threadPriority); 68 t.start(); 69 } catch (Exception e) { 70 exception = e; 71 } 72 }
PS: the concept of ExecuteAndWait struts2 When a long request arrives, it will be executed in a separate thread and return a WAIT result. Therefore, again, the client retransmits the same request at a certain interval in order to find out the status of its process (which is running in the thread).
My problem: In the above case, when the main request (which initiates the thread to call the action) returns with WAIT, and again another request will know the status of the action at this time in my action class if request.setAttribute("test", "test"); execute, that is, the error I mentioned above
java multithreading apache struts2
Hybris Freelance
source share