Thread: Shutdown hooks not working

Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1 Shutdown hooks not working 
    Donator

    Sir Lethal's Avatar
    Join Date
    Mar 2008
    Posts
    2,286
    Thanks given
    9
    Thanks received
    74
    Rep Power
    426
    I'm using the following code

    Code:
    static {		Runtime.getRuntime().addShutdownHook(new Thread(){
    			public void run() {
    				System.out.println("Saving players...");
    				synchronized(this) {
    					for(int i = 0; i < Config.MAX_PLAYERS; i++)
    					if(players[i] != null)
    					save.saveGame((Client)players[i]);
    				}
    			}
    		});
    	}
    Yet when I close the CMD and I log back in im rolledback, I don't understand why. Can anyone help?
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Jan 2011
    Posts
    189
    Thanks given
    6
    Thanks received
    29
    Rep Power
    52
    Why is it static?
    Reply With Quote  
     

  3. #3  
    Donator

    Sir Lethal's Avatar
    Join Date
    Mar 2008
    Posts
    2,286
    Thanks given
    9
    Thanks received
    74
    Rep Power
    426
    Quote Originally Posted by Desmin View Post
    Why is it static?
    Not sure, heres the foll code if that helps

    Code:
    public static PlayerSave save;		static {
    		Runtime.getRuntime().addShutdownHook(new Thread(){
    			public void run() {
    				System.out.println("Saving players...");
    				synchronized(this) {
    					for(int i = 0; i < Config.MAX_PLAYERS; i++)
    					if(players[i] != null)
    					save.saveGame((Client)players[i]);
    				}
    			}
    		});
    	}
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Jan 2011
    Posts
    189
    Thanks given
    6
    Thanks received
    29
    Rep Power
    52
    Is the hook even being run? Does that "Saving players..." message show?
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Jul 2014
    Posts
    15
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Um, idk how to fix that but you could make a ::restart command for you on the server and everytime you do that it will save everyone.. thats recommended if you got vps.
    Reply With Quote  
     

  6. #6  
    Registered Member
    Join Date
    Jan 2011
    Posts
    189
    Thanks given
    6
    Thanks received
    29
    Rep Power
    52
    Quote Originally Posted by 2pac4evah View Post
    Um, idk how to fix that but you could make a ::restart command for you on the server and everytime you do that it will save everyone.. thats recommended if you got vps.
    Well, that's not really useful. The whole idea behind a shutdown hook is to save important data before the thread shuts down from, say, some bug that crashes the server.
    Reply With Quote  
     

  7. #7  
    Donator

    Sir Lethal's Avatar
    Join Date
    Mar 2008
    Posts
    2,286
    Thanks given
    9
    Thanks received
    74
    Rep Power
    426
    Quote Originally Posted by Desmin View Post
    Is the hook even being run? Does that "Saving players..." message show?
    I'm not sure really.. it doesn't say saving players at all. I don't understand what I'm doing wrong.
    Reply With Quote  
     

  8. #8  
    Registered Member
    Join Date
    Jan 2011
    Posts
    189
    Thanks given
    6
    Thanks received
    29
    Rep Power
    52
    Quote Originally Posted by Sir Lethal View Post
    I'm not sure really.. it doesn't say saving players at all. I don't understand what I'm doing wrong.
    I added you on skype, I'll try to help you there.
    Reply With Quote  
     

  9. #9  
    Donator

    Sir Lethal's Avatar
    Join Date
    Mar 2008
    Posts
    2,286
    Thanks given
    9
    Thanks received
    74
    Rep Power
    426
    Quote Originally Posted by Desmin View Post
    I added you on skype, I'll try to help you there.
    Alright, my skype is kaelan.keller
    Reply With Quote  
     

  10. #10  
    q.q


    Join Date
    Dec 2010
    Posts
    6,519
    Thanks given
    1,072
    Thanks received
    3,535
    Rep Power
    4752
    the shutdown hook isn't ran when u exit the cmd, you need to use System.exit()
    Reply With Quote  
     

  11. Thankful user:


Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Client not working for You? READ!
    By Edge in forum Tutorials
    Replies: 59
    Last Post: 02-06-2020, 09:27 AM
  2. Shutdown Hook Not Working?
    By Slawth Baws in forum Help
    Replies: 5
    Last Post: 02-25-2013, 08:14 PM
  3. Replies: 0
    Last Post: 03-22-2012, 01:08 AM
  4. [PI] Would this shutdown hook work?
    By The Situationist in forum Help
    Replies: 3
    Last Post: 05-17-2011, 04:26 PM
  5. Replies: 17
    Last Post: 11-30-2007, 04:15 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •