Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Property File Reload problem

 
Prashant R Kataria
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am running a web application under tomcat server. We are using one library which is taking some inputs from the Property file.

Now if we change the values in the property file than we are forced to reload our application to take that change in to effect.

But we want that change in effect without reloading our application, and we can not change the existing code in the library that we are using.

So is there any way to reload that property file?

Any comment is invited.

Thanks,
Prashant Kataria
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the library isn't equipped to reload the file there isn't much you can do about it without changing its code.
 
Prashant R Kataria
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually we are thinking of having custom class loader which can reload that property file for each request.

But don't know will it work or not and also how to implement it.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would work only if you can ensure that the library is loaded through the custom classloader, and that there are no live references to any classes of the library at the time you want to unload it. That could get very tricky.

I take it you don't have the source code to the library in question, and that it doesn't provide a way to change those properties programmatically?
 
Prashant R Kataria
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes we can not change anything in library. But library doesn't have that property file in it, it is put in to classpath by me.

We are using tomcat server, so I think, I will have to extend the existing Tomcat server's classloader.

Is it workable?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said, it may work if you can ensure that the classloader that loads the library can be unloaded (meaning there are no references to any of its classes).

And by classloader I mean one that you wrote, and which is used to load the library and nothing else, not one of Tomcat's classloaders. I would strongly advise against messing around with those.

As an aside, I would reconsider using a library that doesn't do what you need done, and which -for whatever reason- can't be changed to do what you need done.
 
Sripathi Krishnamurthy
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try this.
Store the timestamp of the property file in a DB or a text file. Write a new class which will read the timestamp of the property file and if the file is changed, reload the property file and update the reference of the classes that uses this propetry files.This way you dont have to reload the property file at each request. This will be a very costly operation.
But updating references for the changed property file has to be done carefully.
 
Prashant R Kataria
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sripathi Krishnamurthy,

I have 2 question about your solution.
1] How will I reload property file so that it will have changes that I made.
2] How will I update reference in the classes that uses that file as I classes in library doesn't have any setter for that property and I dont have access to the code of that library.
 
Sripathi Krishnamurthy
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


1] How will I reload property file so that it will have changes that I made.

Write a class called PropertyFileListener. This file will use an SQL on a DB table to know that the property file was changed. You can probably use a flag (true or false). If you find true, that means the property file has changed and you need to update this in the application. Then reload the property file using the same class.


2] How will I update reference in the classes that uses that file as I classes in library doesn't have any setter for that property and I dont have access to the code of that library.

For this, I agree with Ulf Dittmer . You need to know which classes from the library use those property files, unload them and reload them again. The other option is to rewrite the libarary which you say you cant for some reason.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using a database isn't really necessary. Just make a note of the file modification date and time at application startup, and then periodically check whether the file modification date/time has changed. If it has, trigger the update. Still, it's quite a complex thing to do, and I'm still curious why you couldn't change the library, which is the right thing to do.
 
Prashant R Kataria
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The library I am using is of my vendor and they haven't provided source code with it nor we have license to change it.

I am calling one method of a class which has some logic that reads the property file from classpath.

I am not aware of what kind of code they have written in it, but I am bound to the contract that I have to have a Property file with particular name in my classpath.

That method is returning me one object. Now if I call that method second time after changing values in property file than I want the new object to be created with new values but that is not happening,it is taking values loaded at first time.
 
Prashant R Kataria
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I unload particular class?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't unload just one class. If you load that class through a special classloader -which in this case means the complete library needs to be loaded through that classloader- you can discard the classloader if there are no more references to any of the classes it loaded. Then you can instantiate the classloader -and the library it loaded- again, which will cause the new file to be picked up. Not for the faint of heart. It will probably be cheaper to pay your vendor to make this change to the library.
 
Prashant R Kataria
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your inputs, I am working over it, I will let you know if there is any update over this issue.
 
Prashant R Kataria
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I found another way of handling class loading in this case.

I can create new folders and put my property file in every folder. Now depending on which property file I want to load I will put that folder in classpath.

I think this will reduce the library unloading problem for me.

I have started working over it and will give you update of the result.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic