Can I use Quartz Scheduler to launch my application? - java

I have a Java desktop application that I'd like to completely exit, and schedule it to launch at a later date.
Is there any way of using Quartz Scheduler for this?
As far as I understand, Quartz requires a Java runtime to be running for it to activate.
I'd like the following functionality, and would not mind using another Java library to achieve this:
Get/Set schedules for execution of a Java application.
Be able to launch the application without having a Java runtime.
Maintain a cross-platform codebase.

Yes you can, you need to wedge it outside the code.

Related

How to integrate java with control M

I have few control-M job running on server. I can perform basic operations like to start/stop or pause any JOB from control M Interface.But there is not a development environment available for Control-M.
I have another java application from where I want to start/stop/pause and other basic stuffs of Control-M.
Till now I am totally blank.I don't know which JAVA API, I should use. Do i need to have development environement of Control-M also.
Could some one please help me on this regard?
You should use Web service functionality of Control-M.The details Example is given with API. Run the bat file for configuration.Provide your parameters.Run ClientGui.java.
if you have provided your correct parameters than you should be able to connect with control-M.Please make a comment if you are facing any issue..
Look at Control-M for Web Services, Java and Messaging. They also just came out with a Automation API but you have to have Version 9 Fix Pack 2

ManagedExecutorService, ManagedTask and ManagedTaskListener alternative for Java SE

I recently built a Java EE 7 web application using GlassFish / Payara.
The web application started long running tasks (> 2 hours) on the underlying operating system on demand. These tasks are basically other programs or scripts written in Python, Ruby or Java and executed using the command line (Apache Commons Exec). Since I wanted to inform the user about the current state of a task and give him the possibility to cancel a running task I used the following Java EE features and libraries.
The following list briefly describes why I decided to use a specific Java EE feature or an external library.
ManagedExecutorService
Injected using #Resource, allowed me to queue Runnables and execute them in an own thread
ManagedTaskListener Implementation
This was the reason why I actually decided to use a ManagedExecutorService and run threads within the application server
The interface gave me four very handy methods (taskSubmitted, taskAborted, taskDone and taskStarting)
This allowed me to update the long running task status (JPA) and inform the user if a state change occurred
Runnable, ManagedTask Implementation
Here I defined the actual long running task by overriding the run() method
To react on state changes I also registered the ManagedTaskListener implementation as previously described
Apache Commons Exec Util
To actually execute the long running tasks the Runnable and ManagedTask implementation simply used apache commons exec
To be able to cancel a long running process I set a ShutdownHookProcessDestroyer per DefaultExecutor
Using defaultExecutor.getWatchdog().destroyProcess(); this allowes me to kill a running task
I know it is not the best idea to misuse a ManagedExecutorService in combination with ManagedTasks to execute such long running tasks, but it worked pretty stable.
But know I would like to run these long running tasks on a different physical machine and execute them using just Java SE. This means I have no ManagedExecutorService and therefore no ManagedTaskListener interface.
Does anyone have experience with this situation? Maybe there is library which provides similar capabilities. I think Google Guava provides something which goes into a similar direction but does not provide the same capabilities.
I am also thankful for other solution approaches.
Thank you very much!
Use the Java SE executors (i.e. ScheduledExecutorService) to submit a Runnable/Callable that makes the necessary updates.
You will have to implement your own equivalent of ManagedTask/ManagedTaskListener, but that should be easily achievable through your Runnable/Callable implementations.
Side note:
When you are using a ManagedTask, this is a perfect scenario to set ManagedTask.LONGRUNNING_HINT=true on your ManagedTask. For example:
managedTask.getExecutionProperties().put(ManagedTask.LONGRUNNING_HINT, "true");

How to create batch file for java-quartz cron job

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.

Job Scheduling in Java

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

Run a program or method at specific time in Java

I just want that my program or method should run at specific date and time.
i have heard about Timer and TimerTask in java API. But don't know exactly how to use it.
If you want to run a java program at a specific time you probably want to look at the OS tools (like cron or at).
If you want to run a method inside of an already running java application then the ScheduleExecutorService, while it may be overkill, is pretty easy to use.
If this is for your own benefit and not for a project I would suggest you look into
http://java.sun.com/javase/6/docs/api/java/util/concurrent/ScheduledThreadPoolExecutor.html which is a replacement for java.util.Timer. If however you want a robust scheduler, I concur with the previous posters with regards to Quartz.
Maybe you should use a third-party library with a higher level API like Quartz and use the SimpleTrigger.
You can run your task inside a Glassfish Java EE server. It supports a Timer Service that fires background tasks at specified intervals. When you're running a cluster of Glassfish servers on different machines, they'll collaborate to fire the task exactly once.
A simpler approach is to rely on cron for Unix systems. At specified times you can run your java task via the java command.
I've also used pycron on Windows, which is a service that emulates cron.

Categories

Resources