SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow Waiting for locked file to be released

    I have a SQLite database file which is locked by the database connection. When I close the connection, although it is closed, it takes some time until the database file is actually unlocked. During this time I can not delete the database file. What is the best way to find when the file is unlocked?
    Code Java:
    this.conn.close();
    System.out.println("Connection closed: "+this.conn.isClosed());
     
    while(databaseFile.exists()){
            boolean result = databaseFile.delete();
            System.out.println("DB Deleted: "+result);
            if(result==true){return result;}
    }

    Any ideas?

  2. #2
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Troy
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is better to run while(databaseFile.exists()){...} in a new thread
    Live Chat software for your web sites

  3. #3
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rei12 View Post
    It is better to run while(databaseFile.exists()){...} in a new thread
    Thank you very much for your reply. Here is what I have now for the delete thread:

    Code Java:
    class Delete_Thread extends Thread {
        private File database_file;
     
        public boolean result = false;
     
        Delete_Thread(File database_file){
            this.database_file = database_file;
        }
        // This method is called when the thread runs
        public void run() {
            while(this.database_file.exists()){
                this.result = database_file.delete();
                System.out.println("DB Deleted: "+this.result);
            }
        }
    }

    Then I use the following code to invoke it:
    Code Java:
    Delete_Thread thread = new Delete_Thread(this.databaseFile);
     
    thread.start();
     
    while(thread.isAlive()){thread.join();}
     
    if(thread.result==true)return true;

    The code above works fine.

    However, if I comment the line System.out.println("DB Deleted: "+this.result); the Thread continues forever.

    May be I am doing something wrong?

    Any help is appreciated.

  4. #4
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SOLVED

    The problem has been the unit test itself

    During the unit test a second connection to the database was opening, that prevented the database deletion until being closed.

    Thank you for your help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •