It's not a secret anymore!
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

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:
at javax.swing.plaf.basic.BasicTreeUI.paintRow(
at javax.swing.plaf.basic.BasicTreeUI.paint(
at javax.swing.plaf.ComponentUI.update(
at javax.swing.JComponent.paintComponent(
at javax.swing.JComponent.paint(
at javax.swing.JComponent.paintChildren(
at javax.swing.JComponent.paint(
at javax.swing.JViewport.paint(
at javax.swing.JComponent._paintImmediately(
at javax.swing.JComponent.paintImmediately(
at javax.swing.RepaintManager.paintDirtyRegions(
at javax.swing.SystemEventQueueUtilities$
at java.awt.event.InvocationEvent.dispatch(
at java.awt.EventQueue.dispatchEvent(
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(
at java.awt.EventDispatchThread.pumpEventsForHierarchy(
at java.awt.EventDispatchThread.pumpEvents(
Don't know if that helps...
Robert Ziel

Joined: Apr 22, 2002
Posts: 28
sounds to me you got a nullpointerexception
maybe when you add some code somone can point out the problem to you
I agree. Here's the link:
subject: Problem w/shutdown hook thread & serialization
It's not a secret anymore!