Clairvoyant1332
Programmer
I'm trying to find a way to have a java program put itself in the background, rather than having the shell do it via "nohup java class" or "java class &". I tried creating a sample program that calls setDaemon() as follows:
I would think that the thread would continue to run after main exits, but that doesn't appear to be the case.
Is there a way to do this, and if so how?
Code:
public class jthread extends Thread
{
public void run()
{
int i;
try { sleep(1000); } catch (InterruptedException e) {}
for (i=0;i<10;i++) {
System.out.println("i="+i);
try { sleep(2000); } catch (InterruptedException e) {}
}
}
public static void main(String[] args)
{
jthread j= new jthread();
j.setDaemon(true);
j.start();
try{ sleep(2500); } catch (InterruptedException e) {}
}
}
I would think that the thread would continue to run after main exits, but that doesn't appear to be the case.
Is there a way to do this, and if so how?