Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7559685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:41:51+00:00 2026-05-30T12:41:51+00:00

I have developed a Java socket server connection which is working fine. When started

  • 0

I have developed a Java socket server connection which is working fine.

When started from a terminal, it starts from listening from client. But when I close the terminal it stops listening.

I need to continue even though the terminal closed by user from where jar file was started.

How can I run Java server socket application in Linux as background process?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:41:52+00:00Added an answer on May 30, 2026 at 12:41 pm

    There are several ways you can achieve such a thing:

    1. nohup java -server myApplication.jar > /log.txt – this is pretty straight forward. It will just put the application in the background. This will work but it’s just not a very good way to do so.
    2. Use a shell wrapper and the above OR daemon app. This approach is used by many open source projects and it’s quite good for most of the scenarios. Additionally it can be included in init.d and required run level with regular start, stop and status commands. I can provide an example if needed.
    3. Build your own daemon server using either Java Service Wrapper or Apache Jakarta Commons Daemon. Again – both are extremely popular, well tested and reliable. And available for both Linux and Windows! The one from Apache Commons is used by Tomcat server! Additionally there is Akuma.

    Personally I would go with solution 2 or 3 if you need to use this server in the future and/or distribute it to clients, end users, etc. nohup is good if you need to run something and have no time to develop more complex solution for the problem.

    Ad 2:

    The best scripts, used by many projects, can be found here.

    For Debian/Ubuntu one can use a very simple script based on start-stop-daemon. If in doubt there is /etc/init.d/skeleton one can modify.

    #!/bin/sh
    
    DESC="Description"
    NAME=YOUR_NAME
    PIDFILE=/var/run/$NAME.pid
    RUN_AS=USER_TO_RUN
    COMMAND=/usr/bin/java -- -jar YOUR_JAR
    
    d_start() {
        start-stop-daemon --start --quiet --background --make-pidfile --pidfile $PIDFILE --chuid $RUN_AS --exec $COMMAND
    }
    
    d_stop() {
        start-stop-daemon --stop --quiet --pidfile $PIDFILE
        if [ -e $PIDFILE ]
            then rm $PIDFILE
        fi
    }
    
    case $1 in
        start)
        echo -n "Starting $DESC: $NAME"
        d_start
        echo "."
        ;;
        stop)
        echo -n "Stopping $DESC: $NAME"
        d_stop
        echo "."
        ;;
        restart)
        echo -n "Restarting $DESC: $NAME"
        d_stop
        sleep 1
        d_start
        echo "."
        ;;
        *)
        echo "usage: $NAME {start|stop|restart}"
        exit 1
        ;;
    esac
    
    exit 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a java client server app based on socket programming. I am
I have a Java app, connecting through TCP socket to a server developed in
I have developed a number of classes which manipulate files in Java. I am
We have our own custom calendar in our portal which is developed in Java.
We have hundreds of websites which were developed in asp, .net and java and
I have a project to develop a client server application in java . This
I have developed a java program that runs fine in Mac OS X (10.6.7).
I have developed a Java ME application for CLDC platform. It works fine when
I have developed a Java Swing application, which uses the SwingWorker class to perform
I have developed an applet java with Eclipse, which is included in MyPage.html. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.