I have a JMS object appended to request object and in the doPost() method, the object's get method is being called to get current topic data which will be sent to client in response continuously.
On another user request concurrently, I do not see in the doPost() method, the get message being called or rather am receiving empty/null string from the call.
How to make the method be responsive for concurrent requests/users.
On Debug: While debugging in eclipse, I sometimes see that both threads receive getMessage data alternatively.
<jms:listener-container connection-factory="connectionFactory" task-executor="jmsTaskExecutor" destination-type="topic" concurrency="5">
<jms:listener destination="abc.topic" ref="abc" method="receive" />
</jms:listener-container>
<bean name="jmsTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="2"/>
<property name="maxPoolSize" value="50"/>
<property name="threadNamePrefix" value="some-queue-thread"/>
</bean>
<bean id="jmsTopicTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="pubSubDomain" value="true"/>
</bean>
@Component("abc")
public class abc {
private String msg;
public synchronized void receive(String msg){
this.msg = msg;
}
public synchronized String getMessage(){
return msg;
}
}
@Component
@Controller
public class ForwardController extends ServletForwardingController
{
@Autowired
abc topicObject;
@Override
@RequestMapping("/xyzPath")
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
request.setAttribute("autowired", topicObject);
request.getRequestDispatcher("/xyz").forward(request, response);
}
return null;
}
@WebServlet("/xyz")
public class xyz extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) {
abc topicObject = request.getAttribute("autowired");
while(true){
System.out.println("start"+Thread.currentThread.getId());
String msg = topicObject.getMessage();
response.getWriter.write(msg);
System.out.println("stop"+Thread.currentThread.getId());
}
}
}
What is the right way to call topicObject.getMessage() concurrently