• 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

Help! Must prevent termination of one app when second app is terminated

 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have written a java application that dynamically loads and runs other java applications on the same JRE. I'm having a problem where if I close all the applications that mine started (meaning mine and only mine should be the one running) the whole JRE is closed when the last application is closed, and my application ends as well.
Is there a way of preventing this? I'd like to have it so that my application stays running until I explicitly terminate it.
 
author
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not excactly sure how you're instantiating the other threads (i.e. how much control you have over their threads), but there may an issue with the daemon/non-daemon nature of the thread. When only daemon threads are left running, the application will terminate. How about the way the other threads are being terminated? How about how they are created (i.e. are new threads being created or is the main apps thread being used to instantiate new runnable objects?). I guess what I figuring out as I type this is perhaps a bit more info is required
Sean
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's happening is that my app (MyApp) is loading the main class of other applications using URLClassLoader, and then using Method.invoke() to run their "main" methods. This runs the application with the added benefit of having both MyApp and all the other applications running on the same JRE.
Problem:
Suppose MyApp runs three apps: App1, App2, and App3. So now we have 4 apps running on the same JRE. I close App1. Now MyApp, App2, and App3 are still running. If I close App3, MyApp and App2 are still running. If I close App2, App2 closes and so does MyApp, leaving no more java apps running. This example is order-independant (i.e., I could have closed App3 first).
I'd like to keep it so that MyApp keeps running even though all the apps it has run have closed.

Originally posted by Sean MacLean:
I'm not excactly sure how you're instantiating the other threads (i.e. how much control you have over their threads), but there may an issue with the daemon/non-daemon nature of the thread. When only daemon threads are left running, the application will terminate. How about the way the other threads are being terminated? How about how they are created (i.e. are new threads being created or is the main apps thread being used to instantiate new runnable objects?). I guess what I figuring out as I type this is perhaps a bit more info is required
Sean


 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is your program a Thread or Runnable? If so, just put a while(true) loop in the run() method. This will keep it running until you explicitly tell it to stop (with Ctrl-C or whatever your OS uses).
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it's not a thread or a Runnable.

Originally posted by Angela Ann:
Is your program a Thread or Runnable? If so, just put a while(true) loop in the run() method. This will keep it running until you explicitly tell it to stop (with Ctrl-C or whatever your OS uses).


 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your program DO anything after is starts the other 3 apps? Perhaps it just thinks that it is done?
 
Popeye has his spinach. I have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic