I ported a Java web application which used JDK 1.5 and ran under Tomcat 5.5 to now use JDK 1.7 and running under Tomcat 7. I am tasked with developing a Java batch program that will be scheduled. Many of the classes used by the batch process are also used by the web app as well.
Ten years ago I wrote a batch process to use concurrent scheduler. What are some ways today to implement a scheduled batch process using the environment I mentioned above?
Edit:
It has been suggested that I use quartz or ScheduledExecutorService. After taking a look at both of those solutions, I think they may provide more than what I need. At the moment, there exists a batch process that is basically a Java program scheduled to run as a Windows NT Server scheduled task and this approach works well enough for the existing batch process. The new batch process that I will develop can follow this approach as well but next I have a deployment question. The .class files and the .properties and the .jar files used by the batch process are in a separate folder from the web application in webapps. What I need is an automated deployment strategy for the batch processes only. I will mark my original question as answered and ask a new question about the deployment.
Spring Quartz is made for this job:
http://docs.spring.io/spring/docs/1.2.5/reference/scheduling.html
Related
I would like to write a program that sends an automated email based on a timer that runs constantly. I would then like to somehow export this program from eclipse to a computer that does not run the ide, and run it constantly in the background. I have figured out the code to send emails through java, my question is more regarding how to export this project as an application (or something) that can be run on any computer without running it through the eclipse IDE.
Any help, or directions to a better a resource to learn from, would be greatly appreciated.
The simple (manual) approach to turning a Java program into something that runs outside Eclipse:
Create a runnable JAR following the instructions here: http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftasks-37.htm.
If your application depends on library methods that are not part of the Java SE library, pay particular attention to the "select library handling strategy" step.
Run the application from the command line as follows:
$ java -jar yourapp.jar arguments ....
Obviously, you need at least a Java JRE installation on the execution platform to run java, and you should have configured your system (the $PATH or %PATH% environment variable) so that typing java runs the correct thing.
If you are using a build system like Maven, Ant, Gradle and so on, you can automate the step that generates the JAR. (In fact, you can automate the entire build ... and break your dependency on any IDE.)
I DO NOT recommend trying to create an "executable" for your Java application. For a start, executables cannot be run on any computer. They can only be run on computers running a specific operating system / OS family. A second problem is that you are effectively embedding a JRE in your application. That makes applying the latest Java security patches difficult.
As for the problems of keeping the application running "constantly" and sending emails at specific times, that is just Java programming.
Use Timer & TimerTask - e.g. http://www.mkyong.com/java/how-to-run-a-task-periodically-in-java/
Use a job scheduler. For instance Quartz has an easy to use API for running jobs on a fixed schedule: http://quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-06
You need to create a runnable executable. You can do this by following these steps: http://www.wikihow.com/Create-an-Executable-File-from-Eclipse
Regarding the timer/scheduler, you may consider using Windows Task Scheduler (on Windows platform) or cron (*nix platform).
You will probably need to provide more information about the requirements you have for the timer in order to get a more specific answer there.
We've developed a small app using play!, and it runs standalone on a user's computer (Windows XP or Windows 7), as the users don't have network access. Currently, it runs within a console/command window. I would like to make it so there's no console window in the taskbar where play is running--really, mostly because the users are prone to closing the the window. I came up with a couple of ideas, but I was hoping for some validation or other ideas.
First, I was thinking of running Java via javaw, which is typically what runs for GUI applications running Java--but what would I run? I guess I could run the Winstone Servlet container with the WAR output of play! (mentioned as a solution to the other stackoverflow question below).
Second, I was thinking of trying to wrap it in a windows service.
This question is similar, but slightly different (I don't mind installing play!, which just involves unzipping the framework):
Deploy Play! application as executable jar
Has anyone used either of these techniques, or is there a better way? Pros/Cons/Examples?
Thanks!
Update: Any comments about Winstone? It turns out that due to security constraints, we'll not be able to [easily] create services or scheduled tasks (as SYSTEM). Thanks again.
I have done something similar for a few applications. The steps I carried out are
Create a bat file that launches the play app. This could be as simple as play run or play start
Create a scheduled task that executes on system startup, using SYSTEM as the user profile to run the command as.
This approach has been working on my internal systems for well over a year.
Alternatively you can use yajsw to wrap your play application as a windows service. It works really well and is easy to set up.
The only issue I have encountered is that on one of my box running on Windows Server 8 R2, some of the jobs are duplicated when the scheduler kicks off. I am not convinced it is directly related to yajws and I have not been able to reproduce the error on other environments with the same setup.
I managed to work around it by adding a synchronization block in my doJob method.
Have a look here for info for setting up yajws with play.
I am not sure if play would work on winstone. A list of application servers known to work with play can be found here.
You will need to war your play application with play war myapp -o myapp.war and test it first.
I ended up creating a batch file that runs "play run", and a runnable JAR that calls "start /B runPlay.bat" as a system call. This way, the console window doesn't start up at all. It works great so far. There seem to be a variety of solutions, but this was fairly simple.
Is it possible to write a cron job using java quartz and triggering through windows batch file because after so much searching there is no standalone particularly for java-quartz
"So much searching"? This was the first link returned by Google.
If I understand your question right, you want to execute java process as a windows service. If that is correct, wrap your java service (could be quartz as well) using tanuki wrapper and can install it as windows service. Or as #duffymo suggesting you can also use cron trigger too.
I have a Pure Java Process which needs to be run every day at certain time.
This is a temporary job, so i don't wanted to create a new environment to configure this job.
strong text
Is there any way to configure this batch at certain time in Eclipse or IBM RAD?
Is there any plug in available for that.strong text
Regards,
Lokesh.
To my knowledge there is no standard facilities available in Eclipse to support "run code X at time Y", so you need to turn to operating system facilities.
If you can make a simple program launchable with "java -jar" you have many options. FOr Windows many different EXE-that-launch-jar products exist (we use winsw to launch java as services) and you can then use normal scheduling (e.g. at) to invoke your code.
I want to run a Java program on a specific date.
I am developing a J2EE application that allows you to schedule Selenium test launch (JUnit) on a specified date..
Are there any solutions to do this? can you point me to technology that can help me to do this?
any help is appreciated:)
thanks for your help
You provided very little information. You can schedule launch in scheduler of your operating system (like cron in Linux), or you can run a task from within your Java process, if the process is constantly running. For this see Quartz Scheduler.
Not knowing enough details, I would recommend using Quartz. You can see an example of using it here.
You could use crond or Windows Task Manager.
If you have a Java process running from now to the time it needs to start, look at Quartz.
If you need to have a Java process started from nothing, you must ask your operating system to invoke it for you. For Linux check the "at" command.
Cron on Unix, and Cron for NT on WindowsNT platforms (XP-Windows 7, Windows Server 4.0+).
Why reinvent the wheel?
If you want to create and package modular java server-side tasks (that you can then schedule in any particular java scheduler of your choice) check out the open source project called soafaces. Let's you create modular java Tasklets and also give them web based GUI customizer (customizer part is optional and based on google gwt).
Scheduling can be implemented in many ways, it is also bit IO intensive, so if needed u might want to use non-java solutions
However you want to have java solutions may be below links should help you
Spring Way : https://spring.io/guides/gs/scheduling-tasks/ and https://dzone.com/articles/schedulers-in-java-and-spring
Non Spring solution: https://github.com/knowm/Sundial