You can try this: public class Main { public static class ShutdownHook { public static void register(final Runnable runnable) { register(runnable, 0L); } public static void register(final Runnable runnable, final long timeout) { final Runtime runtime = Runtime.getRuntime(); final Thread shutdownHook = new Thread(runnable); runtime.addShutdownHook(new Thread() { @Override public void run() { try { shutdownHook.start(); System.err.println("going to wait for " + timeout + " ms."); shutdownHook.join(timeout); if (shutdownHook.isAlive()) { System.err.println("timeout. halting."); runtime.halt(-1); } System.err.println("joined."); } catch (final Throwable ignore) { System.err.println("exception in shutdown hook."); ignore.printStackTrace(System.err); } } }); } } /** * @param args */ public static void main(String[] args) { final long shutdownTimeoutMillis = 5000L; final long shutdownSleepMillis = 500L; ShutdownHook.register(new Runnable() { @Override public void run() { System.err.println("going to sleep for " + shutdownSleepMillis + " ms."); try { Thread.sleep(shutdownSleepMillis); } catch (final InterruptedException ignore) { } System.err.println("awoken"); } } , shutdownTimeoutMillis); System.exit(0); } }
Post your Comment
shutdown option - Java Beginners shutdown option I want to shutdown the computer,if the user clicks a button named shutdown. Can any one help me how to shut down the computer by action perform of a button
Scheduler Shutdown Example Scheduler Shutdown Example In this section we will see how to shutdown...() method then it will execute (fire) any jobs. Shutdown process of scheduler
call a constructor call a constructor How do you call a constructor for a parent class
call ireports call ireports how to call jrxml file in jsp or servlets pls give one example any one? please send one example any one
Iphone call Iphone call Do you have other method to make a call on Iphone,without openUrl
making call making call Hi, Is it possible to make a call from application with out quitting application in iOS 4? hello, this the code for call...]; [phoneStr release]; hello, this the code for call to a number
conference call conference call hi am a java beginner I want to develop a simple conference call system over a LAN can u please enlighten me on the basics that I have to do and kno first
VoIP Call VoIP Call VoIP Call quality Network testing and monitoring vendors are betting you will as they peddle new call quality management applications..., and businesses embracing VoIP can't afford to make assumptions about call quality
How to call servlet in JSP? How to call servlet in JSP? How to call servlet in JSP
call function in php call function in php What is the call function in PHP please explain
what is an ajax call? what is an ajax call? can u please explain the correct usage of an ajax call in jsps and java script
tomcat jsp call DLL tomcat jsp call DLL Where can i find Example of use JSP under Tomcat environment call DLL
Call UIViewController over RootViewController Call UIViewController over RootViewController Hi, i have created the window based application.. but not sure how to call the UIView over RootViewController. Thanks
call to a member function call to a member function While uploading the data on server i am getting following error... call to a member function children
UIWebView call javascript function UIWebView call javascript function Hi, I am developing web browser for iPhone and iPhone devices. I want to call the java script in my html page from UIWebView. Please let's know how to call JavaScript function from objective c
Call a servlet on click of hyperlink Call a servlet on click of hyperlink Call a servlet on click... to call a servlet</h2><br/> <a href="<%=request.getContextPath()%>/ServletConstructor">Click to call servlet</a> <
how to call static method how to call static method class A { //some code } class B extends class A { static method() } class C { } //how to access static method() from B to C
how to call static method how to call static method class A { //some code } class B extends A { static method() } class C { } //how to access static method() from B to C
https call in AJAX - Ajax https call in AJAX Hi, I am trying to call a https URL in my AJAX script which is in my JSP. But it is not getting the reponse from the url i gave.. am using IE6. suggestions needed.. and more urgent Hi Friend
how call ireports in jsp how call ireports in jsp please send me code any one for calling ireports in servlet-jsp program i am trying to call the ireports in servlet and jsp error is occurred exception: javax.servlet.ServletException
timeout on shutdown hookNils September 16, 2011 at 6:17 PM
You can try this: public class Main { public static class ShutdownHook { public static void register(final Runnable runnable) { register(runnable, 0L); } public static void register(final Runnable runnable, final long timeout) { final Runtime runtime = Runtime.getRuntime(); final Thread shutdownHook = new Thread(runnable); runtime.addShutdownHook(new Thread() { @Override public void run() { try { shutdownHook.start(); System.err.println("going to wait for " + timeout + " ms."); shutdownHook.join(timeout); if (shutdownHook.isAlive()) { System.err.println("timeout. halting."); runtime.halt(-1); } System.err.println("joined."); } catch (final Throwable ignore) { System.err.println("exception in shutdown hook."); ignore.printStackTrace(System.err); } } }); } } /** * @param args */ public static void main(String[] args) { final long shutdownTimeoutMillis = 5000L; final long shutdownSleepMillis = 500L; ShutdownHook.register(new Runnable() { @Override public void run() { System.err.println("going to sleep for " + shutdownSleepMillis + " ms."); try { Thread.sleep(shutdownSleepMillis); } catch (final InterruptedException ignore) { } System.err.println("awoken"); } } , shutdownTimeoutMillis); System.exit(0); } }
Post your Comment