This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Spring and the fly likes A process safe question on Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "A process safe question on Spring" Watch "A process safe question on Spring" New topic
Author

A process safe question on Spring

Ray Clark
Ranch Hand

Joined: Aug 16, 2012
Posts: 52
We have a class at work with a main method that is run from a UNIX shell script. From what I understand it runs fine if it is started once but has problems if 2 of them are running at the same time.

The class might be something like this:



As you can see the class uses Spring for dependency injection.

The question is, if two MainClass objects are running at the same time on the same server will Spring inject the same AnotherClass object (scoped as a Singleton) into both MainClass objects that are running?

Would the two MainClass objects be running in their own JVM so Spring would inject a unique AnotherClass object into each of them?

I'm not sure how this would work. Any suggestions?

Thank You.
Kathleen Angeles
Ranch Hand

Joined: Aug 06, 2012
Posts: 122

The 2 runs will be in their own jvms, having their own Spring contexts, thereby having their own AnotherClass Spring-singleton instances.
Ray Clark
Ranch Hand

Joined: Aug 16, 2012
Posts: 52
Thank you Kathleen. That confirms what was going on with my program.

Thanks.
 
Don't get me started about those stupid light bulbs.
 
subject: A process safe question on Spring
 
Similar Threads
Design and implement a stringed musical instrument class
using setter method in spring
Java Inheritance
Core Container dependency Injection Behaviour?
Making two classes work together (newbeginner)