Hello, I am trying to run a thread on web server. The following is part of the code.
which checkmail() is another class that will read all email messages from particular account and update statistic into database. I have succeeded in executing this program in my Windows PC by running it in the command prompt. My question is how to run this program on a redhat linux7.1 (no xwindows) web server? Do I execute it with "java undelivered &" in shell to make it execute in the background? If true, so how do I stop the thread if needed? (assume it is too heavy etc.) And where should I put the class files? Is there any restriction for thread to work in web server? Any help will be highly appreciated. By the way, I am glad the server is working today. Have a nice day, Steven Ho
Do I execute it with "java undelivered &" in shell to make it execute in the background?
Yes, that would probably work. However this means that you have to manually start it every time your computer restarts. Probably better to create a script in /etc/rc.d/init.d/ that you can use to start it, stop it, and check it's status. Let's call that script "mailCheck". Here is a sample script that I use to start my J2EE server:
Some things to note:
I use sudo to force my J2EE server to run as user "apache". I do not want it running as user "root" (the default). In my sudoers file, I have set it up so that root can run the j2ee server as user apache without being asked for a password. If you want to know why not to run this as root, just ask.
Note that you will have to set any required environmental variables inside this startup script - the script will be run with a very limited path and very few of what you would consider "standard" variables
So anytime you want to start your application, you could type <code>/etc/init.d/mailCheck start</code>. When you want to stop it you can type <code>/etc/init.d/mailCheck stop</code>. To check whether it is running, you can type <code>/etc/init.d/mailCheck status</code>. Then you can go into the dirctory for your run level. Since you are not running the X Windows System, you are probably using run level 3. So you would go into the /etc/rc.d/rc3.d/ directory and create a start up and shut down symbolic link back to your /etc/rc.d/init.d/mailCheck program. Start up links start with the letter "S" followed by a number followed by the script name. The number indicates the order for scripts to start. So you would want this to start sometime after your MTA starts (mine starts with S80sendmail) so you might create a start up script with the name S81mailCheck. The shut down scripts work the same way, except they start with a K (for kill). You would want your script to shut down before your MTA shuts down (mine shuts down with K30sendmail) so possibly something like K29mailCheck. So now your script will start whenever the operating system starts, and shut down whenever the operating system shuts down. Did I loose you in this? If so where? Regards, Andrew
By the way, I mention in my description that the samle code is for my J2EE server. However after writing the entire post I realised that my script for starting the rmiregistry was a better fit, so I changed the script but forgot to change the text that goes with it. :roll: Hopefully you can still make sense of it. Regards, Andrew
Joined: Jan 16, 2003
Thank you very much Andrew for answering my question. I will try the solution you posted. Have a nice day.