• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to execute thread on linux web server?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the Linux forum.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
     
    Andrew Monkhouse
    author and jackaroo
    Posts: 12200
    280
    Mac IntelliJ IDE Firefox Browser Oracle C++ Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 15
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank you very much Andrew for answering my question. I will try the solution you posted. Have a nice day.
     
    Curse your sudden but inevitable betrayal! And this tiny ad too!
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic