Kushal Jain
Kushal Jain

Reputation: 3186

Run a java program even after putty terminal closed

I use putty for taking linux machine terminal from my windows machine and run a java program.

Java Class

   try {

        Timer t = new Timer();
        t.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                logger.info(new Date()+"...");
                i=i+1;
            }
        }, new Date(), 3000);

        if(i==50){
            t.cancel();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

This program write a line in every 3 second. If I close the putty it stop running. Program become end, it not writing any more lines in the logger file.

How can I run java program in the backend or even in running state after closing putty terminal ?

Upvotes: 1

Views: 3340

Answers (2)

user8833693
user8833693

Reputation:

Try nohup command:

nohup java -jar test.jar &

Upvotes: 8

Sunshine
Sunshine

Reputation: 449

You can look into using the screen utility on linux which continues to run after after you logout of your session.

https://www.linode.com/docs/networking/ssh/using-gnu-screen-to-manage-persistent-terminal-sessions

Upvotes: 1

Related Questions