wood burning stoves 2.0*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A process safe question on Spring