[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

Database connection on linux

Hi,

I have a JAVA web application running on Linux which works fine.  The connections are taken from the tomcat (web-server) connection pool.  

The problem is, there is a scheduled task which needs to bew run, using cron, every day.

It runs, but it does not use the connection from tomcat, because (I think) it is not running in hte web-server environment.  It is a mysql database.  Is there any other way to connect so that I can avoid this problem, such as having a global datasource?
 
0
rosshind
Asked:
rosshind
4 Solutions
 
girionisCommented:
> It runs, but it does not use the connection from tomcat, because (I
> think) it is not running in hte web-server environment.  It is a mysql
> database.  Is there any other way to connect so that I can avoid this
> problem, such as having a global datasource?

You will need to simulate the web application somehow in order to use the conenctions from Tomcat's database pool. You can have a utility task that acts like a datasource if you want though. This class will be used by Tomcat and any other application that needs access to the database, but you will have to manualyl create the pool and the connections since it woudl be Tomcat-independent.

0
 
lhankinsCommented:
What is the scheduled task written in...?   Is it a shell script...?   Is a java program...?

If it is a java program, you could move the code into your webapp and have it executed from within your servlet container.   For example :

1. Modify the code to use the same datasource lookup connection parameters your webapp does.
2. Expose a hook which kicks off this code via url (either kick it off from a JSP/Servlet, add a struts action which kicks off the code, etc).
3. Adjust your cron job to just hit the URL in your webapp (instead of running the script manually).

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
objectsCommented:
Instead of using cron you could load a servlet on wtartup of your webapp that uses a Timer to run the task (from the webapp).
0
 
girionisCommented:
I believe I provided a general idea of what should be done and was expecting the user to come back for a more specific question in order to help more. I think I deserve some points.
0
 
kiranhkCommented:
I gave the link to the proper documentation on setting up the Datasource and accessing them !!!
 I think I also deserve some points.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now