Sometimes the only way things ever got fixed is because people became uncomfortable.
That's another questionable item. Directly manipulating threads in JEE apps is often a problem. In fact, returning to the JEE webapp environment the JEE spec absolutely forbids spawing threads or doing other thread operations on servlet service methods or Enterprise JavaBeans.Venkat S Prasad wrote:I had used Thread.Sleep() as well to check if the system is working , it is working but only for the time mentioned in the sleep method only.. but he main method needs to run continuously without any halt
Sometimes the only way things ever got fixed is because people became uncomfortable.
Tim Holloway wrote:
That's another questionable item. Directly manipulating threads in JEE apps is often a problem. In fact, returning to the JEE webapp environment the JEE spec absolutely forbids spawing threads or doing other thread operations on servlet service methods or Enterprise JavaBeans.Venkat S Prasad wrote:I had used Thread.Sleep() as well to check if the system is working , it is working but only for the time mentioned in the sleep method only.. but he main method needs to run continuously without any halt
Sometimes the only way things ever got fixed is because people became uncomfortable.
Venkat S Prasad wrote:but he main method needs to run continuously without any halt
Paul Clapham wrote:Also... to know that the application is terminating, you can add a shutdown hook which can tell you that. Here's a tutorial which shows you how to do that.
Paul Clapham wrote:
Venkat S Prasad wrote:but he main method needs to run continuously without any halt
No, the main method should just start the connection. Presumably that starts a thread which listens for messages and calls the onMessage() method for each message it receives. I don't see how calling Thread.sleep should affect anything. Perhaps you could explain a bit more about how you know that the whole application (not just the main method) is stopping.
Venkat S Prasad wrote:Thanks for your reply.. by seeing my code could you please guess why my init() method is returning back to main method without calling onMessage() when there are lot of messages that need to be consumed.. it should not happen in this case ight.. as it is a asynchronous process the onMessag needs to be calledtill the last message gets consumed and then return to main method.
As per your request in any message consumer class when ever any message listener starts it needs to start consuming or producing any messages immediately but it is not happening in this case , it is just going back to the previous call where the init method has been called.. but if i keep Thread.sleep it is consuming the messages in that time where the main method has been waiting stae and then quitting.. i want to know why after starting connection it is taking time to connect to onMessage method
Al Hobbs wrote:try this
onMessage is called asynchronously whenever there is a message.
After you call init() the program ends, so no messages are consumed or maybe 1 if it arrives before it exits.
Venkat S Prasad wrote:Thanks .. it Worked but the messages that are consumed are not in an order .. example if three messages gets consumed .. in that two messages prints the message in logs and then they are hitting database .. it is creating a problem