Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring synchronization issue
    primarykey
    data
    text
    <p>I know that question about reusing prototype beans was asked many times, but my question means more than this.</p> <p><strong>What is the problem:</strong></p> <p>I start asynchronous tasks in handler (prototype bean) in for-lookup. but I can't start the next asynchronous task before the previous reach some milestone. So I have to proceed for-loop only after the previous task invokes a special method.</p> <p><strong>What the questions:</strong></p> <ol> <li><em>How to wait in for-loop before some method call in another bean?</em></li> <li><em>Can I invoke proceedLookUp() method of current prototype bean from another beans?</em></li> </ol> <hr> <pre><code>@Service(value = "Request.Start") @Scope("prototype") public static class Start { public Start() {} private Object lock; @Transactional public void handler(Request request, Response response) { for (int i = 0; i &lt; request.getAmount(); i++) { Utils.asyncProcessStart(); //Can't start the next async process before the previous rich some defined milestone lock.wait(); } } public void proceedLookUp() { lock.notify(); } } @Service public void AsynchronousTask { public void asyncAction() [ //Needed logic, before start the next async task getStartHandler().proceedLookUp(); } public void getStartHandler() { //HOW TO REWRITE NEEDED PROTOTYPE BEAN } } </code></pre> <p><strong>ADDITION:</strong></p> <p><em><strong>What is the problem</em></strong>: I use Activiti framework, which imply some restrictions. I should store some variables to a process (thread) context. I CAN write variables to a global context, BUT CAN'T write to a local process (thread) context before the process (thread) has been started. </p> <blockquote> <p>what you expect to happen, say if request.getAmount() returns 2?</p> </blockquote> <p>I should start two asynchronous processes in two different threads. Each process have <strong>the same set of variables</strong>. I must <strong>write appropriate variables to the local context of each process (thread)</strong>. But, I <strong>CAN'T</strong> do it <strong>before the process (thread) is started</strong> (due to the specific of Activiti framework).</p> <p>For example, each process (thread) should write "id" property to his own local context. I have <em>List ids</em> in <em>handler</em> method</p> <p>So, I should do the next sequence of actions:</p> <ol> <li>Write ids.get(0) as "id"-property to GLOBAL context</li> <li>Start the first process</li> <li>Hang on the for-loop</li> <li>[Inside the first process] write "id" property from global to local context (it is possible inside the first process)</li> <li>Notify appropriate Start bean that it can continue the for-loop</li> <li>Write ids.get(1) as "id"-property to GLOBAL context</li> <li>Start the second process</li> <li>Hang on the for-loop</li> <li>[Inside the second process] write "id" property from global to local context (it is possible inside the second process)</li> <li>Notify appropriate Start bean that it can continue the for-loop</li> </ol> <blockquote> <p>Why can't you just call it synchronously?</p> </blockquote> <p>As you have already understood, there is no guarantee that the first process (thread) write the "id"-property to it local context, before it has been overriden by for-loop for the second process (thread).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload