I have written a code to send mail to user and that's running nicely, but this program i want to place on server side and runs continuously without any client interaction. It should be run automatically after specific time. When server stops then only it will stop.
So can any one help me how to do this...?
Thanks in Advance...
If your server has cron, you can have the job run at scheduled times. Without knowing more about how the application works, and how it knows when it's time to send an email, there's not much more I can say.
You should look at the Quartz and how to start a java process from the command line in your deployment environment (it's slightly different in Windows and *nix, and very different in z/OS).
If I understood correctly, in your case I would just use the at command. You can find a description in its man page1.
Probably calling at with a calculated time from the moment of execution, and adding that to a rc.d script would do it.
Related
I need to execute a shell script in a java program. I figured out that i can use processbuilder and runtime.exec.. but my webserver times out every 180 sec but my script execution takes more than that..i do not want to use process for this approach.. is there any other way where i can use thread for this execution.
thanks.
I'm assuming that the response from the script is intended for humans to read.
Good interface design, and human nature, suggests that if your script is taking over 180 seconds to run, then it should be run separately from the web server. On linux, I would suggest putting it into 'cron', and letting it run on a regular basis. You would only serve the results of the script via the web server, with a response time in seconds instead of minutes.
If your script depends on parameters from the http request, or other information that is only available from within the web server's environment, you have the following choices.
If you can figure out the likely combinations of parameters, run the
script automatically for each combination of parameters,
again only serving the results through the web.
If the majority of the time is spent in a single command, and the
results of that command don't change much between runs, move that
command into a separate script that runs automatically, and use the
results of that separate script to build the web response.
Break the response up into segments, only showing a portion of the
data for each request, allowing the user to page through the
response. The script would be rewritten to only request the
necessary data for the current page, reducing the amount of time
needed to obtain that data.
Rewrite the script in a compilable language, which might gain you enough time to make running it for every request reasonable. However, if the problem is a database query, this won't do you any good. You'd have to go with option (3), whether you rewrote it in a compilable language or not.
Without additional information, like an example of the script, or a description of where you're getting the results from, that's the best I can do.
A process can run several threads, but they still are parts of the process.
So, all threads inside a java program are the threads of the java process, and a thread cannot run another program's threads.
A shell script is ran by a program : the shell program ! (/bin/bash or /bin/sh)
Anyway a shell script will mostly ran other programs inside several other processes.
No, you cannot run a shell inside a thread of java.
In general, if you have code that is separate from your Java program, such as code that is in a separate script, then there is no justification for why your code would execute an outside script when that code could be instead integrated into the program. It is insecure at best. Your basically allowing arbitrary code to be executed by your program since the outside script is editable. What you are doing sounds to me almost like it should be confined either a unit test or a build task.
As a unit test task and you could use a threaded JUnit runner to run your outside script during the test phase of your project.
Also, separately from your program, you could also execute it using a Gradle task and by using the parallellforks option that Gradle has.
from a JavaServerAddin I trigger an agent that invokes another program on a domino server. The program takes a little time to run. Normally, the addin schedule does not interfere with the program.
I would like to check from my JavaAddin if the program is still running and avoid invoking the agent when the result of the check returns true.
Anyone any idea, how to do this?
I've tried this (http://www.rgagnon.com/javadetails/java-0593.html) and other samples, but it only returns tasks that are running on the server but not inside Domino
Did you consider to issue a SHOW TASKS to the console. With -XML you get something that is easy to parse.
Session s = ...;
String result = s.sendConsoleCommand("yourserver","SHOW TASKS -XML");
Hope that helps
I am working on a plugin for the Serversoftware Bukkit which should restart it. So I have added the main Function which checks for the right arguments and then starts Bukkit. But before it starts Bukkit it should wait for Bukkit to shutdown before I start it again. I know I could add a timeout but I hope there is a better way. So does anybody know how to do that?
One way would be to check the os with System.getProperty("os.name"); and run the ad hoc command for that specific platform (for example: Linux and Windows).
When you start multiple java processes they all seem to have the same identifiers, which seems to be your problem. "differentiating" the processes is your problem, not killing them.
So either you could create the process yourself programatically, and thus be able to note the PID that is used for the process. Then killing it would be VERY simple:
http://blog.igorminar.com/2007/03/how-java-application-can-discover-its.html
Another idea would be to use JPS to get information on all the java processes. A simple sudo algorithm is discussed here:
http://bluepedia.blogspot.com/2008/11/jps-differentiate-between-multiple-java.html
Hope I could be of some help..
How can I make a java program such that it is always running on the system (such as a daemon or service), but only allow one instance of the program to run? I would like it to start either when I run the program or when the system starts (either is fine).
Take a look at commons-daemon
For First part of your Question you need to make a thread running continuously,
for second part of your question look here
I've used this to run a Java program as Windows service service : http://wrapper.tanukisoftware.com/ , with good results.
I have a batch file that starts a Java process in a Windows 2003 server. As per the security policy, the users of that machine are logged off forcefully, if the user is inactive for a certain period of time. The problem is that when the user is logged out, the process also dies.
I scheduled a new task (Control Panel -> Scheduled Tasks) and selected the option of 'When my computer starts' and gave the user account details there. But it doesn't seem to have any effect, the user is still logged out and the process dies. Is a reboot necessary to make this change effective? And after the reboot, will I achieve what I'm expecting (keeping the process alive)?
Alternatively, will running this process as a Windows Service solve the problem? If so, can you please let me know how I can make a Java program or a batch file to run as a Windows Service? I would prefer not to use any other third party tools or libraries.
Thanks
If you want it to run under Scheduled tasks you have to make sure you don't have "only run when user logged in" checked, which usually means you need to supply a password.
A windows service would be the normal way to do this: the Java service wrapper is 3rd party but loads of people use it.
If you really wanted to not use a 3rd party method you could use svrany.exe (http://support.microsoft.com/kb/137890) on WIndows NT or later, but it is not designed specifically for Java.
Wrapping the process with srvany.exe and launching as a service would work as well.
http://support.microsoft.com/kb/137890
I don't know it this is relevant but we are using a flag to the jvm so it does not shutdown on logoffs
"java -Xrs"
Link to suns description of -Xrs
I'm using Java Service Wrapper to start the java process as windows service.
I guess it works similary to the srvany.exe mentioned in the previous posting.
As per my analysis,
The Idle Solution will be writing a VC++ (.net) Windows Service creation program to launch the .bat / .exe as a System service with all the required call back methods to SCM.
Note :
1. Wrapping the process with srvany.exe would not work as it does not have any call back process to the SCM (Service Control Manager).
2. And java service Wrapper is a third party API (many are LGPL licensed).