How to shutdown an ExecutorService?

The typical pattern is: executorService.shutdownNow(); executorService.awaitTermination(); When calling shutdownNow, the executor will (generally) try to interrupt the threads that it manages. To make the shutdown graceful, you need to catch the interrupted exception in the threads or check the interrupted status. If you don’t your threads will run forever and your executor will never be … Read more

How to get shutdown hook to execute on a process launched from Eclipse

I used the following hack at the end of my main method to get around the problem: if (Boolean.parseBoolean(System.getenv(“RUNNING_IN_ECLIPSE”))) { System.out.println(“You’re using Eclipse; click in this console and ” + “press ENTER to call System.exit() and run the shutdown routine.”); try { System.in.read(); } catch (IOException e) { e.printStackTrace(); } System.exit(0); }

How can I run a Perl script as a system daemon in linux?

The easiest way is to use Proc::Daemon. #!/usr/bin/perl use strict; use warnings; use Proc::Daemon; Proc::Daemon::Init; my $continue = 1; $SIG{TERM} = sub { $continue = 0 }; while ($continue) { #do stuff } Alternately you could do all of the things Proc::Daemon does: Fork a child and exits the parent process. Become a session leader … Read more

Shutting down a computer

Create your own function to execute an OS command through the command line? For the sake of an example. But know where and why you’d want to use this as others note. public static void main(String arg[]) throws IOException{ Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec(“shutdown -s -t 0”); System.exit(0); }

How to shut down the computer from C#

Works starting with windows XP, not available in win 2000 or lower: This is the quickest way to do it: Process.Start(“shutdown”,”/s /t 0″); Otherwise use P/Invoke or WMI like others have said. Edit: how to avoid creating a window var psi = new ProcessStartInfo(“shutdown”,”/s /t 0″); psi.CreateNoWindow = true; psi.UseShellExecute = false; Process.Start(psi);

How do I exit a WPF application programmatically?

To exit your application you can call System.Windows.Application.Current.Shutdown(); As described in the documentation to the Application.Shutdown method you can also modify the shutdown behavior of your application by specifying a ShutdownMode: Shutdown is implicitly called by Windows Presentation Foundation (WPF) in the following situations: When ShutdownMode is set to OnLastWindowClose. When the ShutdownMode is set … Read more

How do I shutdown, restart, or log off Windows via a bat file?

The most common ways to use the shutdown command are: shutdown -s — Shuts down. shutdown -r — Restarts. shutdown -l — Logs off. shutdown -h — Hibernates. Note: There is a common pitfall wherein users think -h means “help” (which it does for every other command-line program… except shutdown.exe, where it means “hibernate”). They … Read more