Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

autoterminating service  RSS feed

 
Andrew Gaydenko
Greenhorn
Posts: 10
Firefox Browser Linux Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I need some kind of executor service which is like java logger is:

- doesn't need explicit shutting down
- executes tasks queue and treminates when all other user's threads are terminated.

The thing is I don't understand how to hook this condition - "all other user's threads are terminated". A daemonizing threads in a pool also doesn't help - threads are interrupted immediately on above condition.

Any tricks?
 
Carey Evans
Ranch Hand
Posts: 225
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The actions registered by Runtime.addShutdownHook() will be run when System.exit() is called, when there are no no-daemon threads left, or when Control-C or similar is pressed. Is this what you want?
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew:
A daemonizing threads in a pool also doesn't help


Can you explain as to why doesnt it help?
If all the worker threads in a pool are daemons then the pool will automatically shutdown when the user threads die i.e. your threadpool will not hold a JVM shutdown.

Toggling thread.setDaemon(true); to true and false will unhold and hold JVM termination:


[ July 07, 2008: Message edited by: Nitesh Kant ]
 
Andrew Gaydenko
Greenhorn
Posts: 10
Firefox Browser Linux Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems like I have resolved the issue. Please, excuse me for cross-foruming (I have created new topic here after some answerless period at SDN) - I have decribed the situation here:

http://forum.java.sun.com/thread.jspa?messageID=10327012

The main conclusion I have got is to not to use java logger for debugging a termination of concurrent app
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!