简体   繁体   中英

Run Java app continuously on Shared Web host

I apologise if this is an obvious question, but lets say I had a java app that constantly queries yahoo finance API for current stock quotes. Could I store this program and have it run continuously on a shared web hosting server without being in constant communication with a client (my desktop)? Would I need to install a JVM into my hosting space?

Along with this, would the app be able to create text and write to text files the same way as if it was operating on a desktop computer? This way I could query the app once a day to download the text file and not worry about the program taking up my computer's RAM.

Finally, is there a way to determine how much RAM my app is using since my web host only offers x amount of RAM.

If there is any literature you can supply that can give me some need to know general data on this subject, I'd be very grateful.

Could I store this program and have it run continuously on a shared web hosting server without being in constant communication with a client (my desktop)?

If this it's a webapp and they're running something like Tomcat (I think AWS Elastic Beanstalk more or less does), then yes. Just make sure you flag a filter or a servlet as load-on-startup in the deployment descriptor (web.xml), and then scheduling API calls should be easy enough. I'd start with ScheduledExecutorService for that. Java webapps, unlike how PHP, Python, and Perl are usually run, are more like applications in that code is alive for the life of the web server, not just the life of the request, so a single instance will serve some path for the lifetime of the webapp's deployment. Resources set up in init() (like threads) won't even be GCed until shutdown. Threads might not even be GCed (hint: don't ignore the destroy() method.

Would I need to install a JVM into my hosting space?

Oh, well, if you have "hosting space," you can do what you want, so why even worry about this being "web hosting" and not just rent-a-server? There actually are two flavors of hosting: one gives you a VM/physical machine, and you do what you want (think EC2), and the other gives you neutered access to a few scripting languages that start with P, Apache with cgi-bin, maybe modphp, and a managed MySQL instance that you have limited control over.

Along with this, would the app be able to create text and write to text files the same way as if it was operating on a desktop computer? This way I could query the app once a day to download the text file and not worry about the program taking up my computer's RAM.

Maybe. Look into File.createTempFile() . Or store your data in a DB and rematerialize it as a CSV, or something, when a request for /give-me-my-data comes in. But really, memory is so cheap, and this sort of data compresses so well I'm not sure I'd worry about it, yet.

Finally, is there a way to determine how much RAM my app is using since my web host only offers x amount of RAM.

Runtime.getRuntime().*memory()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM