java - POJO Property change listener - Ideal way -


I am developing a REST based web application that uses asynchronous third for some data (using websites) The system will call. So the browser -> rest -> my webpages -> other apps -> my webpage-> browser communication between my webpage for other web apps is asynchronous and I can track responses to a request using only some identifiers I am Therefore, I will call & lt; Counter & gt; Request and response & lt; Counter & gt; Response will be , where both the counter will be the same.

To map the answer to the request, I am setting a command, counter, flag with a bean. I keep a loop for a while, whether it is setting the flag or not, it keeps on checking. Once I receive a response, set the flag, while the loop leaves and I know that the data is available.

Is this the right way?

The class is set to be below the bean,

  Public Zero set AllProperties () {bean.setCommand (commandString); Bean.setCounter (counter); Bean.hasResponse (wrong); }  

Snippet in the webservice

  bean.SetAll properties (); SendToApplication (beans); Int checkCounter = 0; While (! Bean HAS Response & amp; Checkcuper & gt; 0) {if (bean.hasResponse) {checkCounter ++; // loggers and other logic here}}  

gives a lot of loop value Asynchronous operation also consumes a CPU time (trying to add a delay - a quick sleep - when using such a loop).

I "wait ()" and "notify ()" /

  synchronize (bean) {while (! Bean.hasResponse)} { < P> In the code which is waiting for a response, bean.wait (); }}  

In the code that processes the response and updates the bean:

  synchronize (bean) {bean.hasResponse = true; Bean.notifyAll (); }  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -