aspose file tools*
The moose likes Threads and Synchronization and the fly likes Problem w/shutdown hook thread & serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Problem w/shutdown hook thread & serialization " Watch "Problem w/shutdown hook thread & serialization " New topic
Author

Problem w/shutdown hook thread & serialization

Buzz Andersen
Ranch Hand

Joined: Aug 28, 2001
Posts: 54
Hi everyone,
I'm having a particularly perplexing problem. I have an application that uses a custom subclass of a JTree to hold some data. I want this data to persist after the user closes the application, so my idea was to have the application serialize the Tree when it exits, and deserialize it when it starts again.
Initially I accomplished this using the "windowClosing()" method, and it worked fine, but then I realized that on some platforms (Mac OS X, for instance), the "WindowClosing()" event is not necessarily fired when the user quits the application.
So, I switched to having the serialization done in a shutdown hook thread. Now, whenever the application shuts down, it reaches the point where it starts the serialization, but then simply hangs!
Does this sound like a deadlock problem, or does anyone else have any ideas on what might be causing the hang? Two things that might be of note:
1. I started testing to make sure that my Tree isn't null before I try to serialize it (my theory being that maybe the object was being disposed before I tried to serialize it)--and it isn't.
2. If I try to serialize a new instance of the Tree class rather than my existing one, everything works fine--the class serializes and the application exits normally.
Any ideas, or do you think I'm even in the right forum?
Thanks in advance,
Buzz Andersen
Buzz Andersen
Ranch Hand

Joined: Aug 28, 2001
Posts: 54
One other thing: when I run the program on Mac OS X, it doesn't hang when shut down, but rather crashes with this message:
java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTreeUI.paintRow(BasicTreeUI.java:1309)
at javax.swing.plaf.basic.BasicTreeUI.paint(BasicTreeUI.java:1120)
at com.apple.mrj.swing.MacTreeUI.paint(MacTreeUI.java:137)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:39)
at javax.swing.JComponent.paintComponent(JComponent.java:395)
at javax.swing.JComponent.paint(JComponent.java:691)
at javax.swing.JComponent.paintChildren(JComponent.java:498)
at javax.swing.JComponent.paint(JComponent.java:700)
at javax.swing.JViewport.paint(JViewport.java:710)
at javax.swing.JComponent._paintImmediately(JComponent.java:3836)
at javax.swing.JComponent.paintImmediately(JComponent.java:3676)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:455)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:124)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:154)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:337)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)
Don't know if that helps...
Buzz
Robert Ziel
Greenhorn

Joined: Apr 22, 2002
Posts: 28
hi,
sounds to me you got a nullpointerexception
maybe when you add some code somone can point out the problem to you
Robert
 
jQuery in Action, 2nd edition
 
subject: Problem w/shutdown hook thread & serialization