I have taken a simple standalone client example from examples provided in quartz 1.6 download bundle to run a job. But at the start up of the weblogic server, job is running twice. Is there any settings or something required to run the job only once at the start-up of the server? If any code snippet or external link will be much helpful.
Thanks
I had similar issue in tomcat. In my case I had my application bound to root path and to /appName path. So for instance there was app1.jar which was bound to / and to /app1 paths. As a result app was initialized twice in the server and hence quartz was triggered twice.
Related
I deploy a spring boot application on azure (app service), but it takes many time to get started (20 minutes sometimes), I always have in the logs this line with many occurences :
Waiting for response to warmup request for container myapp_id_on_azure_0_917c0e77. Elapsed time = 326.0884541 sec
I seems to wait something to effectively start the application ... but what ?
Anyone have tips ?
FYI : I execute : java -jar /home/site/wwwroot/my_app.jar for starting my application. I not define any server port in application.properties on my spring boot application. I also verify that on "general settings" of the app service the option "always on" is enabled ...
FYI : I execute : java -jar /home/site/wwwroot/my_app.jar
From this sentence, I can probably guess that you are using the linux platform.
I think your question is meaningless, in the absence of any log. So there should be no one who can give you a direct and effective solution, but can only provide you with troubleshooting ideas.
Troubleshooting steps
If you use windows platform, you should add web.config under wwwroot folder.
Instead of executing java -jar /home/site/wwwroot/my_app.jar in the command line.
If you use linux paltform, and your webapp use myapp.jar file , so you should use Java SE, like below.
Whatever paltform you use, you shold check application log, find error message, it will help you solve the issues.
I have a spring boot project in which spring scheduler is working fine as i have added logger in scheduler method in my local system using Cron expression.
Problem:
When same spring boot app is deployed over PCF(Pivotal Cloud Foundary) it does not enable the scheduler and no logs are printed neither any error is shown in pcf logs related to scheduler.
While if i hit any controller through postman, logs are printing for that but not of scheduler.
I also provided cron expression value like for every minute in pcf environment variables in app and restarted the app. But that didn't help.
Can anyone suggest me something in this issue?
Thank you in advance for your valuable time!!
When you deploy your application in PCF Cloud space, it takes your code, scan it against available buildpacks unless explicitly provided by user and then creates a container image also known as Droplet using code, build-pack and base container.
If you use cloud config to manage the configurations for spring boot scheduler, it uses auto configurations to load the properties at runtime. In some cases due to the difference in the OS configuration and loading of these configurations at runtime, there will be mismatch between what timezone your app expects and the one that the server understands.
Most of the time it can be resolved by explicitly defining the timezone configuration in PCF manifest file or command line when pushing the application.
E.g. set environment TZ variable.
cf set-env {app-name} TZ 'America/Chicago'
OR by adding following in manifest.yml file:
env:
TZ: America/Chicago
I would like Flyway to run whenever I deploy a new war to my server.
Does flyway automatically get run when a server is deployed? Do I have to always automate a script which would then the flyway migration command? Or what is the best way to do this?
Server:
The server is a Java Tomcat Server running on Elastic Beanstalk (AWS) that is connected to a MySQL database.
Deployment Process
We run our sql migration scripts on the database manually. Then we upload a new war of the server to Elastic Beanstalk.
This can be useful:
Auto-migration on startup : https://flywaydb.org/documentation/api/
So for Java all it takes is to create scripts (eg. V1__initial_schema.sql, ...), put them under /src/main/resources/db/migration/
and then:
Flyway flyway = new Flyway();
flyway.setDataSource(...);
flyway.migrate();
As the comments said, there may be multiple ways to do this.
ServletContextListener
One common way is to use the hook defined by the Java Servlet spec for being notified when your web app is launching and shutting-down. That hook is the ServletContextListener interface. Add a class to your project implementing the two methods in this interface, one for launch and one for shutdown. In the launch method, run your Flyway code.
The word “context” is the technical term meaning your web app.
contextInitializedYour web app is launching. No incoming web request has yet been handled, and will not be handled until your implementation of this method completes. Run your Flyway migrations here.
contextDestroyedYour web app is shutting down. The last remaining web request has been serviced, and no more will be accepted.
Annotating this class with #WebListener is the easiest of multiple ways to get your Servlet container to register an instance.
Pretty easy.
Your ServletContextListener is guaranteed to be called and run to completion before the first execution of any Servlet (or Filter) in your web app. So this is the perfect place to do setup work that you want finished before your servlets go to work. Flyway seems like a natural fit to me.
Search Stack Overflow for “ServletContextListener” to learn more and see examples, such as my own Question & Answer.
Handling failure
Be aware that stopping a web app’s deployment when something goes wrong (when your ServletContextListener encounters an Exception) is not well-defined in the Servlet spec.
An example might be your Flyway migrations failing for some reason, such as not able to connect to database. At that point you might want to halt deployment of your web app.
See my own Question and Answer and the group of related questions I list in that answer. Tomcat 8.0.33 halts the deployment, and un-deploys the web app, but unfortunately does not report the offending Exception (or at least I could not find any such report in the logs nor in the IDE console while in development mode). The behavior of other Servlet containers may vary.
We have a web application which uses CRON4J scheduling. The Jobs are running twice for same scheduling time. can anybody know why?
we deployed this app on tomcat.
You are definitely registering the Task twice. May be there is another copy of your war deployed, so you actually have 2 instances of your application running ?
If you scheduler is defined in the context listener, check how many times have you defined the context. It will be executed for each context .
You can have multiple context if you use virtual host, or if you define one context in the war (META-INF/context.xml) and other in server.xml (you should not define context here).
I'm looking for a way to properly shutdown (Undeploy) an Java Web Application within the application itself. I've tried System.exit(), but this not only shutdown the webApp but also messes up Glassfish.
I know about the contextlistener, I'm just wondering how to start the shutdown procedure.
Deploying of web applications is the responsibility of application server. I do know how is it in Glassfish but other app. servers (e.g. JBoss, Tomcat etc) have web based management application that allow to do this.
If you want to undeploy application programmatically from the application itself you can use JMX. Refer to the glassfish JMX implementation to know which bean to call. But IMHO I do not think that you really need this.
The usual approach is to use the asadmin undeploy command.
The general form for the command is:
as-install/bin/asadmin undeploy war-name
For war-name, use the literal hello, not the full hello.war name.
For the hello.war example, the command is:
as-install/bin/asadmin undeploy hello
See the following references:
http://docs.oracle.com/cd/E19798-01/821-1757/geyvr/index.html
http://docs.oracle.com/docs/cd/E19798-01/821-1758/undeploy-1/index.html
To undeploy programmatically, you can use JSR-88 though i cant really see a reason as to why you would want to do this. See
http://blogs.oracle.com/japod/entry/using_jsr_88_for_web
http://www.jcp.org/en/jsr/detail?id=88