aspose file tools*
The moose likes Tomcat and the fly likes Beginner question about copying new file to running server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Beginner question about copying new file to running server" Watch "Beginner question about copying new file to running server" New topic
Author

Beginner question about copying new file to running server

Mike Pearson
Greenhorn

Joined: Dec 06, 2009
Posts: 4
I hope I am posting this to the correct forum. If not, please tell me which forun would be the correct one. Thanks!

I am new to j2ee development, although I have a few years of j2se. I need to start a simple j2ee project that provides our company's pricelist on line. As it only gets updated once a month, I don't plan on regenerating it for every request, but provide a static copy. However, once a month I'll need to copy a new file in. Now the question: what is the process for doing this? How would I ensure that the file isn't being read while I write a new one? I'm not looking for code, just a description about how I would go about solving this issue.

Thanks in advance.

Mike P
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10265
    
168

Mike,
Welcome to JavaRanch

The answer to your question, depends on the application server you use. Which application server (and which version) are you using?


[My Blog] [JavaRanch Journal]
Mike Pearson
Greenhorn

Joined: Dec 06, 2009
Posts: 4
I'm using the free Tomcat for development. I'm not really sure what the deployment server will be - probably Apache. Would I need to stop the application, or is there some clever built-in logic that would "lock" the incoming requests until I have copied the new file(s) - just like a database update?

I'm not at the stage of needing this info yet, but it seems an obvious question that I'm going to get asked by my boss. I want to at least pretend I have a clue what I'm doing

Mike
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10265
    
168

Mike Pearson wrote:Would I need to stop the application, or is there some clever built-in logic that would "lock" the incoming requests until I have copied the new file(s) - just like a database update?



If it's a new file that you are adding, then i don't think you would require to "lock" incoming requests. And although i don't have much experience with Tomcat, i do think there's a way to make available the new file without having to stop/re-start the application. I'll move this thread to the Tomcat forum where you might get some help from experienced users.
Mike Pearson
Greenhorn

Joined: Dec 06, 2009
Posts: 4
By "new", I meant updated; that is, it needs to replace an existing file of the same name.

How would you achieve this in the server you know?

Thanks.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10265
    
168

Mike Pearson wrote:By "new", I meant updated; that is, it needs to replace an existing file of the same name.

How would you achieve this in the server you know?



I know about JBoss. In JBoss, if the file is a .jsp file, then for an exploded deployment, the changes are picked up dynamically without having to stop/start the application (also known as redeployment). However, if the file is a .class file then a redeployment is necessary.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10265
    
168

By the way, all this is for a "dev" environment. I wouldn't recommend any of these (even if it works) for a production environment. I have always found that the best and reliable way to update file(s) in an application on a production environment is a restart of the application.
Jeroen Bs
Greenhorn

Joined: Sep 25, 2009
Posts: 9
If the pricelist is static why not use a plain html file ? I dont see the point of using J2EE application server for just displaying a static pricelist. If you want the list to be more dynamic I would recommend using a database to store(and update) the data and jsp etc to generate the view.

In my experience (which is using Jboss and some big J2EE applications) hot deployment is a bliss because it saves a lot of restart time during development but I wouldn't recommend hot deployment it for production. Because sometimes the hot code replacement fails and the server crashes. In a production environment I would stop the server replace the code and restart(and use more than one server to prevent downtime).
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16246
    
  21

JBoss generally uses Tomcat as its JSP/servlet container (although jetty is an option), so the same rules apply to both JBoss and straight Tomcat.

If you have the scanning feature enabled (it comes that way by default) and you update a file that Tomcat finds interesting - or the deployment descriptor as well - Tomcat will restart the application automatically.

There are some caveats, however. From what I've deduced, stuff relating to the environment doesn't get terminated/reinitialized, so you can destablize the apps. The most notable offenses have been with database connection pool-related stuff and servlet init functions. I've never studied it in detail, but it's possible that maybe as a consequence of reloading into a running JVM/classpath, static initializers might not be re-invoked. All I know is it's safer to update JSPs than stuff relating to data services.

The other thing to watch out for is apparently new to recent Tomcat(s). After a redeploy or 2, you end up running out of memory. Seems to be a cleanup problem/Tomcat bug.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Beginner question about copying new file to running server