• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getTreeLock()

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like in LayoutManagers, both for determining the preferred / minimum / maximum size and for layout out the component.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic