Question

I have an ear application (myApp) that runs on a Websphere Application Server (WAS). I have a jar (myJar) that is loaded into the classpath of myApp when the WAS server is started. myJar has a class (MyInitClass) that reads from a db and loads a set of data (myData) into memory. This data gets read many times by myApp. The point is to get myData into memory to prevent doing a db call every time this data is used. This part works great!
The solution I am trying to provide is a manual initialization of MyInitClass. myData gets changed from time to time and I would like to be able to reinitialize MyInitClass from a command line so I don't have to restart the application. Is this possible?
myApp calls a class (MyClass) that has something like this:

public static MyInitClass initClass;

public boolean doStuff()
{
    if (initClass == null)
    {
        // this method loads the data into initClass.myData array
        initClass.dataInitializer();
    }
    else
        // no need to reload initClass.myData
}

I have created code similar to this in another class (MyManualInit):

public static void main(String[] args)
{
    MyClass.initClass = new MyInitClass();
    MyClass.initClass.dataInitializer();
}

When I run MyManualInit from command line it prints all the same debug info that gets printed during the initialization from myApp. But myApp does not recognize that MyInitClass has been reinitialized. I have printed System.out.println(System.getProperty("java.home")) from both processes to validate that I am using the same JRE to run both. Am I doing something obviously wrong here or does it just not work like that? I assumed if I ran MyManualInit on the same JRE it would work. MyClass, MyInitClass and MyManualInit are all in myJar.
Please let me know if you need more info.

Était-ce utile?

La solution

You are mixing things. Websphere runs in an instance of the JVM and your command line program instantiates a new one, and objects do not communicate between different JVMs (at least without some effort, bringing up sockets, etc.)

Actually your code does a lazy initialization of your initClass object, and it should be enough without any command line interaction. Why is it not enough for you?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top