Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 358613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:18:58+00:00 2026-05-12T12:18:58+00:00

Hi I have an Standalone application in which when an user logs in a

  • 0

Hi I have an Standalone application in which when an user logs in a abc.lck file gets created when the application is closed it gets deleted.I have used addshutdownhook() to delete the file when power supply is interrupted that is switching off the power supply when my application is running.My problem is the file is not getting deleted when I manually shutdown the system i.e by start–>shutdown and I should prompt the user with a message to save the changes using cofirm dailog box like in MS Word.Can some one help me
Thanking u
Chaithu

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T12:18:58+00:00Added an answer on May 12, 2026 at 12:18 pm

    Use deleteOnExit method instead of adding shutdownhook. However, take a look at this sample,

    class Shutdown {
    
      private Thread thread = null; 
      protected boolean flag=false;
      public Shutdown() {
         thread = new Thread("Sample thread") {
         public void run() {
            while (!flag) {
               System.out.println("Sample thread");
              try {
                  Thread.currentThread().sleep(1000);
                  } catch (InterruptedException ie) {
                   break;
                  }
            }
            System.out.println("[Sample thread] Stopped");
         }
       };
      thread.start();
      }
    public void stopThread() {
        flag=true;
     }
    }
    
    class ShutdownThread extends Thread {
        private Shutdown shutdown = null;
        public ShutdownThread(Shutdown shutdown) {
          super();
          this.shutdown = shutdown;
        }
        public void run() {
             System.out.println("Shutdown thread");
             shutdown.stopThread();
             System.out.println("Shutdown completed");
        }
    }
    
    public class Main {
      public static void main(String [] args) {
       Shutdown shutdown = new Shutdown();
       try {
         Runtime.getRuntime().addShutdownHook(new ShutdownThread(shutdown));
         System.out.println("[Main thread] Shutdown hook added");
        } catch (Throwable t) {
          System.out.println("[Main thread] Could not add Shutdown hook");
        }
    
        try {
           Thread.currentThread().sleep(10000);
        } catch (InterruptedException ie) {}
        System.exit(0);
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hai I have developed a standalone application in which when an user logs in,
I have created an standalone application in which i want that when the user
I have a standalone application in which I have to prompt the user with
I have written a standalone Java application that I've packaged into a jar file
I have created ASP.net Web application which uses Crystal Report to show reports. Now
I have implemented a standalone java application which uses the swing framework for GUI.As
I have a standalone Java application written with Apache Camel which I want to
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
I have a standalone application that needs to connect to a Sybase database via
I'm going to be integrating with an existing application which will have an attached

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.