wood burning stoves 2.0*
The moose likes Linux / UNIX and the fly likes how to execute thread on linux web server? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "how to execute thread on linux web server?" Watch "how to execute thread on linux web server?" New topic
Author

how to execute thread on linux web server?

Steven Ho
Greenhorn

Joined: Jan 16, 2003
Posts: 15
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
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Moving to the Linux forum.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi,
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


    The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander

    Joined: Mar 28, 2003
    Posts: 11404
        
      81

    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
    Steven Ho
    Greenhorn

    Joined: Jan 16, 2003
    Posts: 15
    Thank you very much Andrew for answering my question. I will try the solution you posted. Have a nice day.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: how to execute thread on linux web server?
     
    Similar Threads
    SingleThreadExecutor suggestions needed
    Help needed with java.util.Timer
    Threads doubt
    Thread and Timer
    Set Timer