Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getTreeLock()  RSS feed

 
A. Gazola
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

I�d like to know how useful is the method Component.getTreeLock() from Swing... the javadoc is vague... Can anybody show me an example of the usage of this method? Is this method necessary or the SwingUtilities.invokeLater() and invokeAndWait() alone are enough for Swing multithreading programming?

thank you
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would just use invoke later, trying to manage locks and so on gets deep in issues that are lengthy to discuss and do not lend themselves to simple examination. I was reading about invoke later this morning, that will be the tool to use.
 
Campbell Ritchie
Sheriff
Posts: 53734
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know myself; what I do know is that you start a Swing app with the invokeLater() method, then you would need new threads for anything else which takes time. There is a new class called SwingWorker whihc is designed to start new threads, but I can't remember how it works. Sorry.


Anybody else??
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OP: Try this - Bug ID: 4294865 Deadlock caused by bug in java/awt/Window.java

Campbell:


I never have comprehended how this code runs, something to do with the new ob() but I do not see how control drops into the curly braces. The call to start() ..... if it works for many people, fine; but how the curly braces bind with the call a few lines later escapes me.
 
Campbell Ritchie
Sheriff
Posts: 53734
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know myself, I am afraid.


Anybody else?
 
A. Gazola
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems that getTreeLock is useful when you are extending an existing Swing component...
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tree Lock is useful when - as you said - but more to the point when a Swing object needs to get information that is stored in the tree.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like in LayoutManagers, both for determining the preferred / minimum / maximum size and for layout out the component.
 
Suraj Chandran
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general you don't need to ever use getTreeLock() in Swing. Using invokeLater is enough to ensure thread-safety until unless your own code does something really funny. Having said that I still find people writing layoutContainer() method(when creating their own layout managers) synchronized over the object returned by getTreeLock(). I am not sure whether it's absolutely necessary in all cases. You must know why treelocks are used at the first hand. Whenever componenets are validated or updated or blah blah blah... the Component's code will obtain the lock over that component. Now what if some other thread tries to do the same? So it's necessary that tree lock is used during such activities. But we dont need to care about it much, until unless you are dwelliung really deep in to AWT internals.

Cheers, Suraj
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!