Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is there a thread that runs outside the jvm

 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking for a type of thread that does not need the JVM to run, such as if I start task manager and I end the javaw.exe process, my program should still run...

Are there any threads like that in java?

--thanks
devasia
 
Henry Wong
author
Marshal
Pie
Posts: 20880
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Devasia Manuel:
I am looking for a type of thread that does not need the JVM to run, such as if I start task manager and I end the javaw.exe process, my program should still run...

Are there any threads like that in java?

--thanks
devasia


Well, once the JVM exits, all threads started by the JVM will be terminated also. So, when you say "does not need the JVM", you are talking about an external process, which you can start with a Runtime.exec() call.

Henry
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im not quite sure what you mean, could you please give me an example??
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Devasia Manuel:
Im not quite sure what you mean, could you please give me an example??


Threads always run inside a process.
Any java code always needs a jvm i.e. without a JVM you can not run any java code.
So, if you want something to run without a jvm, it can not be a java code but an external non-java process. This is what Herny meant i.e. you need to start an external process that will continue to run even after the jvm exits.
For example, if you have a shell script that keeps on polling a directory to look for new files. You want this script to start from a java program but still want it to continue after your java program exits.
Then, you can start this script using Runtime.exec(). Irrespective of whether the java code that started this script is alive or not this script will continue to run.

In a nutshell,

There is no java thread that can run outside jvm but there can be a non-java thread that runs outside the jvm. You can start such threads using Runtime.exec()
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, i think i get it thanks!!
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you want is the task manager for the OS. You can program it to start your application at times you choose. So if you have something that needs to be done at 2am every tuesday, you need to ask the OS to start your program at that time. Windows and Linux both have facilities for this.
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im not looking for the Runtime.exec() method since that only starts processes, I am looking for a way to execute a .jar file after the JVM has been shut down and that .jar file should still be running
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As was pointed out above, a JVM is needed to execute a jar file. No JVM means no active Java process.

You can use Runtime.exec to start a second JVM that executes the jar file. Once that's up and running you can exit the first JVM. I think that would not terminate the second JVM; that's easy to find out, though.
[ September 27, 2008: Message edited by: Ulf Dittmer ]
 
Ananth Chellathurai
Ranch Hand
Posts: 349
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the user ends precess of javaw.exe your jar can not run anymore. There is no way a jar could run out of JVM.

Regards
Ananth Chellathurai
Sysvine Technologies
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic