How can I share a static field between 2 class loaders?

Hi,
I've been googling for 2 days and it now seems I'm not understanding something because nobody seems to have my problem. Please, somebody tell me if I'm crazy.
The system's architecture:
I've got a web application running in a SunOne server. The app uses Struts for the MVC part and Spring to deal with business services and DAOs.
Beside the web app, beyond the application context, but in the same physical server, there are some processes, kind of batch processes that update tables and that kind of stuff, that run once a day. Theese processes are plain Java classes, with a main method, that are executed from ".sh" scripts with the "java" command.
What do I need to do?
"Simple". I need one of those Java processes to use one of the web app's service. This service has some DAOs injected by Spring. And the service itself is a bean defined in the Spring configuration file.
The solution is made-up of 2 parts:
1. I created a class, in the web app, with a static method that returns any bean defined in the Spring configuration file, or in other words, any bean in the application context. In my case, this method returns the service I need.
public class SpringApplicationContext implements ApplicationContextAware {
     private static ApplicationContext appContext;
     public void setApplicationContext(ApplicationContext context) throws BeansException {
          appContext = context;
     public static Object getBean(String nombreBean) {
          return appContext.getBean(nombreBean);
}The ApplicationContext is injected to the class by Spring through the setApplicationContext method. This is set in the Spring configuration file.
Well, this works fine if I call the getBean method from any class in the web app. But that's not what I need. I need to get a bean from outside the web app. From the "Java batch process".
2. Why doesn't it work from outside the web app? Because when I call getBean from the process outside the web app, a different class loader is executed to load the SpringApplicationContext class. Thus, the static field appContext is null. Am I right?
So, the question I need you to please answer me, the question I didn't find in Google:
How can I share the static field between the 2 class loaders?
If I can't, how can I load the SpringApplicationContext class, from the "Java batch process", with the same class loader my web app was started?
Or, do I need to load the SpringApplicationContext class again? Can't I use, from the process, the class already loaded by my web app?
I' sorry about my so extensive post...
Thank you very much!

zibilico wrote:
But maybe, if the web service stuff gets to complicated or it doesn't fulfill my needs, I'll set up a separate Spring context, that gets loaded everytime I run the "Java batch process". It'll have it's own Spring configuration files (these will be a fragment of the web app's config files), where I'll define only the beans I need to use, say the service and the 2 DAOs, and also the DB connection. Additionally, I'll set the classpath to use the beans classes of the web app. Thus, if the service and DAOs were modified in the app server, the process would load the modified classes in the following execution.You'll almost certainly have to do that even if you do use RMI, Web services etc. to connect.
What I suggest is that you split your web project into two source trees, the stuff that relates strictly to the web front end and the code which will be shared with the batch. The latter can then be treated as a library used by both the batch and web projects. That can include splitting Spring configuration files into common and specific, the common beans file can be retrieved from the classpath with an include. I regularly split web projects this way anyway, it helps impose decoupling between View/Controller and Model layers.
On the other hand, you might consider running these batch processes inside the web server on background threads.

Similar Messages

  • Hello there - how can I share my iTunes library between two users on the same computer? I put the library in a shared folder between both and have selected this library on both as well, but when I update iTunes with music etc it only appears on one?

    Hello there - how can I share my iTunes library between two users on the same computer? I put the library in a shared folder between both and have selected this library on both as well, but when I update iTunes with music etc it only appears on one?

    Thank you Joe - I tried this but it's only showing a teensy amount of music - the stuff on the second users account as opposed to the giagntic library on the 'main' account. I actually went to a Genius Bar and they said that apple doesn't really want you to share music between accounts - parents don't want to hear their kids music etc. Which seemed strange, but it might be the case sadly   Thanks anyway!

  • How can I share my LR catalog between Mac Mini and MacBook Pro?

    How can I share my LR Catalog between my Mac Mini and MacBook Pro?

    Your Lightroom license key is
    a. Single user / owner
    b. You are allowed two active installations, with one in use at any point in time.
    c. It is cross platform Mac and or PC.
    d. You can install / uninstall as many times it is necessary, as long as you meet the criteria above.
    The latest updates can be accessed from the link below.
    Product updates

  • How can I share apps using bluetooth between two ipads

    How can I share files/apps between two ipad air via Bluetooth. Thanks alot.

    You cannot. That connectivity is not supported by Bluetooth.
    Airdrop supports file sharing via w-fi:
    OS X Yosemite: Use AirDrop to send files to devices near you
    Barry

  • How can I share my itunes libraries between two users on different log ins on the same PC?

    Ive recently bought my wife and iPhone 4, and we have a shared library. But she clearly downloads her own apps and music choices direct from the store to her phone, so wants to maintain her own log in etc. How can I share the library in my iTunes on my log in on the same PC to her iTunes on her log I'm on the same PC. its windows Xp machine with latest itunes version.
    Ive followed the online instructions for sharing thus far, and the share library does not appear in either iTunes. ie It aint working!
    Thanks in advance

    When you say you have a shared library... you mean you have a networked external hard drive that you are sharing?
    In iTunes, generally...when the term Shared Library is used, it's speaking to sharing a specific computer's library over the network with different computer.
    I would think it would be better to do what ya'll have been doing (one log in acct/one computer) and have her create her own Apple acct and each of you log in and out whenever purchasing music apps etc. and then setup individual playlists and pick specific playlists to sync with each individual iPhone.
    If you don't want each other to know what you're buying then...disregard what I just said

  • How can I share my iTunes library between user accounts in iTunes 11

    Since upgrading my iTunes library to Version 11 I can no longer share the library between user accounts on the same Mac.
    The 2nd user is asked to create oir use an iTunes library, but when it is pointed to the Media folder it cannot share it.
    Previously in iTunes 10 it all worked fine.
    How can this be done please?
    The library is in a shared areas that we both have Read/Write permissions to.

    jc_hering wrote:
    that works for anything he purchases after he creates the new account.  What about his current music that currently resides in my itunes library?  How can I get his current music out of my library into his new account/library??  Thanks..
    Copy it to his computer into his iTunes library and authorize his computer with the iTunes account used to purchase them..
    You cannot tranfser items from one iTunes account to another. Purchased items remain part of the iTunes account is was purchased with.
    iTunes account - used to purchase items
    iTunes library - where purchases (and CD RIPs) go on the computer

  • How can I share ONE thunderbird profile between XP x64 and Windows 7 dual booting on the same machine?

    I have a primary XP profile and associated mailboxes/accounts. I am dual-booting to Windows 7 and want to share only that XP profile so that all of my mail appears (and is synchronized) in the Thunderbird browser regardless of which OS I boot to. This seems as simple as pointing the Win 7 mail account local profile to the original XP profile, but that doesn't work. And - please - don't point this question to the response regarding sharing profiles between windows and Linux. That thread hasn't helped. Thanks in advance

    Well I have no idea hat thread your talking about, but regardless the process is always the same, use the profile manager to create a new profile and point the profile manager to the profile you wish to use.
    see https://support.mozilla.org/en-US/kb/profiles-tb#w_restoring-a-profile-backup
    and
    http://kb.mozillazine.org/Moving_your_profile_folder_-_Thunderbird

  • How can I share files in airdrop between mac and phone without having setting turned to "everyone"?

    I'm trying to utlitise airdrop between my MBP and iPhone 5s. I have the same icloud account for both, but when I have airdrop set to "contacts only" on either device the other is not visible. I have to set either device that I am trying to send to as visible to Everyone for it to show up on the other.
    I have myself in my contact book as well so I should technically come up as a contact I would think? I'd rather not have to have visibility set to "everyone" if I can help it.
    Any advice?
    Thanks

    Handoff Continuity Troubleshooting

  • HT1631 How  can I share and sync passwords between  iMac and iPad

    I'm in password ****!!!!  My memory is not what I once was and managing passwords on my iMac and iPad is making me crazy.  The iMac is the home planet at work for the iPad and it use it all day... the iPad is my device of choice when at home. 
    The value of a strong password cannot be understated in these times!!!!
    Is there an easy way to sync passwords between the two.  I find I spend way to much time  resetting passwords because I simply cannot remember them.
    Again... and again... and again... is the story of my life.
    Help
    mike

    The following may help:
    If you are using Safari on both devices and you have iOS 7.0.3 or later on the iPad and OS X Mavericks 10.9 or later on the Mac, iCloud Keychain may be what you want: iCloud: Frequently asked questions about iCloud Keychain
    There are other options available with 3rd party software. Two popular ones are https://lastpass.com and https://agilebits.com/onepassword

  • How can I share my iTunes library with 2 iTunes accounts?

    How can I share my iTunes library between me and my wife?
    I do not want to set-up 2 seperate accounts on my mac. Do not want to do home sharing or anything like this. 
    I just would like to connect my iPad to ONE itunes library and at the same time connect my wifes iPad to the SAME itunes library. Can this be done? How? Thanks! Maybe the answer is something really easy like "just connect both to the computer and sync them".
    Thanks!

    g71.engstrom wrote:
    I just would like to connect my iPad to ONE itunes library and at the same time connect my wifes iPad to the SAME itunes library. Can this be done? How?
    Plug them in and use them.
    That is all you need to do.
    In the answer from Apple I do not find anything about how the 2 exisiting iTunes accounts will be handled.
    They will be handled fine.
    All purchases from both iTunes accounts can be sync'd to both/either iPads with no problem.
    I have three iTunes accounts (me and two daughters), 3 iPhones, an iPad and a few iPods.
    Any/all content can be sync'd to any device, no problems.

  • How can I share Pin variable between two packages?

    Hi every one,
    Is there any one who knows how can I share Pin variable that it is defined with OwnerPin between two packages in java card( with eclipse 3.1),I studied Sharing Interface subject and I knows it teorical but I can not do it practical .
    I can share primitive data type but I can not share Ownerpin.
    If anybody has some sample codes or knows any link ,please inform me.
    My code is same as below:
    //In Server Side
    package ginaPack;
    import javacard.framework.*;
    public class GinaApplet extends Applet implements GinaInterface{
    OwnerPIN pin;
    private GinaApplet (byte[] bArray,short bOffset,byte bLength) {
        pin =new OwnerPIN(PIN_TRY_LIMIT,MAX_PIN_SIZE);
              byte PinTemp[] = new byte[4];
              PinTemp[0] = (byte) 0x31;
              PinTemp[1] = (byte) 0x31;
              PinTemp[2] = (byte) 0x31;
              PinTemp[3] = (byte) 0x31;
              pin.update(PinTemp, (short) (0), (byte) PinTemp.length);       
        public Shareable getShareableInterfaceObject(AID clientAID,byte parameter)
              return  this;
        public OwnerPIN getPinShareable()
             return pin;         
         public void process(APDU apdu)
                      //there are some codes in this here
    }//Interface in Server side
    public interface GinaInterface extends Shareable
          public OwnerPIN getPinShareable();
    }//In Client side
    import ginaPack.*;
    public class UserCardApplet extends Applet {
    private UserCardApplet(byte[] bArray, short bOffset, byte bLength) {
         //there are some codes in this here
    public boolean select() {
              final byte[] Gina_AID={(byte)0x47,(byte)0x69,(byte)0x6e,(byte)0x61,(byte)0x41,(byte)0x70,(byte)0x70,(byte)0x6c,(byte)0x65,(byte)0x74};
              AID GinaAID = JCSystem.lookupAID( Gina_AID, ( short )0,( byte )Gina_AID.length );
              if ( GinaAID == null ) // probably not loaded on card
                        ISOException.throwIt( ISO7816.SW_FUNC_NOT_SUPPORTED );//6a 80
              GinaInterface ff = (GinaInterface) JCSystem.getAppletShareableInterfaceObject(GinaAID,(byte)0);
              if( ff == null )
                   ISOException.throwIt((short)0x0903);
    if ( ff.getPinShareable().getTriesRemaining()== 0 ) return false;
    }My problem is in this line :
    "if ( ff.getPinShareable().getTriesRemaining()== 0 ) return false; "when I select my applet this line throw an exception, ff.getPinshareable includes all of OwnerPin methods(such as getTriesRemaining ,check ,reset, update ,...)but all of them throw exception .
    I think firewal does not allow other packages uses this methods .If my guess is right then what should I do for sharing the variables that they are defined with non primitive data type such as (OwnerPin,Signature,...)
    I'd appriciated for any help.
    yours sincerely,
    Orchid.
    Message was edited by:
    NewOrchid

    Applet 1:
    package com.package1;
    import javacard.framework.*;
    public class Applet1 extends Applet {
        private static final byte tryLimit  = (byte)3;
        private static byte[] pinBytes = {(byte)1, (byte)7, (byte)4, (byte)5, (byte)2};
        private Library1 lib;
        protected Applet1(byte bArray[], short bOffset, byte bLength) throws PINException {
            lib= new Library1(tryLimit, (byte)pinBytes.length);
            lib.update(pinBytes, (short)0, (byte)pinBytes.length);
            register();
        public static void install(byte[] bArray, short bOffset, byte bLength) {
            new Applet1(bArray, bOffset, bLength);
        public void process(APDU apdu) {
            byte status=(byte)0;
            lib.resetAndUnblock();
            if (!(lib instanceof Shareable)) status += (byte)2;
            if (!(lib instanceof MyPIN)) status += (byte)4;
            ISOException.throwIt(Util.makeShort((byte)0x90, status)); // sw indicates tries remaining
        public Shareable getShareableInterfaceObject(AID cltAID, byte parm) {
            return lib;
    }Library1:
    package com.package1;
    import javacard.framework.OwnerPIN;
    import javacard.framework.PINException;
    public class Library1 extends OwnerPIN implements Interface1{
        public Library1(byte tryLimit, byte maxPINSize) throws PINException {
            super(tryLimit, maxPINSize);
    }Interface1:
    package com.package1;
    import javacard.framework.PIN;
    import javacard.framework.Shareable;
    public interface Interface1 extends Shareable {
        boolean check(byte[] pin, short offset, byte length);
        byte getTriesRemaining();
        boolean isValidated();
        void reset();
    }Applet2:
    package com.package2;
    import javacard.framework.*;
    import com.package1;
    public class Applet2 extends Applet {
        private final static byte CLA_TEST = (byte)0x80;  
        private final static byte INS_TEST = (byte)0x20;
        private final static byte P1_AUTHORIZE = (byte)0x00;
        private final static byte P1_DOIT = (byte)0x01;
        private final static byte P1_CHECK_SIO = (byte)0x0a;
        private Interface1 sio;
        protected Applet2(byte bArray[], short bOffset, byte bLength) {
            register();
        public static void install(byte[] bArray, short bOffset, byte bLength) {
            new Applet2(bArray, bOffset, bLength);
        public void process(APDU apdu) {
         byte[] buffer = apdu.getBuffer();
            if ((buffer[ISO7816.OFFSET_CLA] == CLA_TEST) ||
                (buffer[ISO7816.OFFSET_CLA] == ISO7816.CLA_ISO7816)) {
                short bytesReceived = apdu.setIncomingAndReceive();
                switch (buffer[ISO7816.OFFSET_INS]) {
                case ISO7816.INS_SELECT:
                    if (!JCSystem.getAID().equals(buffer, ISO7816.OFFSET_CDATA, buffer[ISO7816.OFFSET_LC]))
                        ISOException.throwIt(ISO7816.SW_APPLET_SELECT_FAILED);
                    sio = (Library1)JCSystem.getAppletShareableInterfaceObject(JCSystem.lookupAID(<fill in parameters>);
                    if (sio == null)
                        ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);            
                    break;
                case INS_TEST:
                    switch (buffer[ISO7816.OFFSET_P1]) {
                    case P1_AUTHORIZE:
                        if (!sio.isValidated()) {
                            if(!sio.check(buffer, ISO7816.OFFSET_CDATA, buffer[ISO7816.OFFSET_LC]))
                                ISOException.throwIt(Util.makeShort((byte)0x9A, sio.getTriesRemaining()));
                        break;
                    case P1_DOIT:
                        if (!sio.isValidated())
                            ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
                        sio.reset();
                        ISOException.throwIt(Util.makeShort((byte)0x9A, sio.getTriesRemaining()));                
                        break;
                    default:
                        ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);                   
                    break;
                default:
                    ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
            else {
                ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
    }1. Upload package1
    2. Install Applet1
    3. Select Applet1
    4. Upload package2
    5. Install Applet2
    6. Select Applet2

  • My wife and I have 2 new iPhones and also have a mac book pro and an iMac. How can we share apps, music and contacts between all these?

    My wife and I have 2 new iPhones and also have a mac book pro and an iMac. How can we share apps, music and contacts between all these?

    Use the same Apple ID and password for purchasing in all these devices.

  • How can I share between 2 different accounts.  we have a clinic that serves pediatics and unfortunately, they set up two different accounts within our agency.

    How can we share between two different accounts on the same iPad?  We have a therapy clinic with 2 devices and want to share apps. I did not set up the second one, but how can we fix this ?

         Hi Rosdy, to get the most out of iCloud it is recommended that you use the same account between devices. Thus whenever you buy something on your phone it becomes accessible from your laptop regardless of whether your synced it over usb or not. *
         For more information on iCloud usage please click here.
    * This feature requires that both devices be on the same WiFi network.

  • I have windows, one computer but multi users. home sharing is on. how can i share music between users on one computer?

    I have windows.  One computer but multi users.  Home sharing is on. 2 apple accounts-1 per user. 4 devices-2 iphones and 2 ipods per user.  How can we share music  on one computer between 2 users?

    Hi Justinece, I've solved the problem in this way:
    In my wife user profile I've set in itunes settings/advanced the path to my music library: /Users/"MY NAME"/Music/iTunes/Itunes media.
    Than, from my wife profile using my administrator user and password I've set the "read/write" privileges on the above mentioned folder.
    Finally I've added the folder in my wife's library taking care to not duplicate it ( leave blank the flag in itunes setting/advanced).
    I really don't understand what's the use of home sharing...

  • How can i share purchased apps between 2 diff users on the same mac?

    How can I share purchased apps between 2 diff users on the same mac?

    A purchased app is associated with an Apple ID. A user with a different Apple ID cannot use the app unless they also use the same Apple ID.
    I cannot use my wife's apps nor she mine because each were purchased with different Apple IDs.

Maybe you are looking for