Hello.

I have such a situation: 3 bins are defined in the context. 2 of them are classes of my application (both Runnable ), and 3 are ArrayList . In the first 2 bins there is a link to this bin- ArrayList . I want to add components to this ArrayList in 1 bin, wait for the addition to be completed, then raise the 2nd bin and use the values ​​from this ArrayList . Will such a construction work, is it correct to do this at all?

 <bean name="firstbean" class="com.fistbean"> <property name="list" ref="mainlist" /> </bean> <bean name="secondbean" class="com.secondbean"> <property name="list" ref="mainlist" /> </bean> <bean name="mainlist" class="java.util.ArrayList"> </bean> 

After that, I do this:

 FirstBean f = ObjectFactory.getObject("firstbean"); f.start() // Тут происходит добавления в ArrayList f.join(); SecondBean s = ObjectFactory.getObject("secondbean"); s.start();// Тут из этого ArrayList читаются значения 

Something like this :)

    1 answer 1

    You are not very clearly described, sorry. What does it mean to "raise the bin" - are they not by default (singletons) or what? If not and you want to reference each other from the beans, you may need to make a "proxy" link. In general, the context would be better posted. But in principle, the "ring link" will work by itself without problems ...%)

    • Updated the question. - Vladimir
    • With links there will be no problems. Do you need both bins to represent threads in which asynchronous actions occur? Something seems to me that in this case, you need to run these bins with the help of an ExeButor (you didn’t write where you started them, but I dare to assume that this will not be what you wanted anyway) . And what do you want? If you inherit them from Thread , then it may be called (but this will be a single-executable bin as a singleton), and in my opinion, it’s not good to run your threads. And if it's just from Runnable , then it doesn't seem to be done - RodionGork
    • immense the Runnable and create the thread from the end, just to save space I didn’t describe it in the example code. I'll see the link, thanks - Vladimir
    • If you create a thread with your hands, then you shouldn't do that. Not all (or almost no) application servers with this will work correctly (if I understand you correctly) - I stumbled upon it once. Then with the link you just need to understand. %) (although in my opinion, if you create a thread in a servlet that itself waits until the generated threads complete the work, then you can) - RodionGork