Solved

related to thread

Posted on 2002-04-01
12
169 Views
Last Modified: 2010-03-31
Hi,

I do this to add the child nodes to the model


 tree.fireTreeExpanded(path);
 System.out.println("node structure changed" +     node.getChildCount());

now the problem is that in my expansion listener program

I am doing the expansion in a different thread
hence the System.out displays this
node structure changed0

What should I do so that in the calling program
I can wait till the thread in the listener program is done
and I get the currect result

What is a good approach regd this
Do I have to block the main thread?

Please help
0
Comment
Question by:sanjay_thakur
  • 5
  • 3
  • 2
  • +2
12 Comments
 

Expert Comment

by:rashidkamranbs
ID: 6910951
a join() method call to that thread from the calling program could be helpful ..

0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6911184
How do I find the other thread?
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6912221
You have some solutions :

1. Don't expand on another thread; what you gain by doing that ?
2. Force the client(s) to implement a callback pattern, to notify the expander thread that it has finished. You can do this using interface passed to the other thread and by using a dummy lock monitor object which you'll lock when you fire the event and unlock when you get called thru thew callback methods of your interface.

Anyway I believe this is not so good design; will be harder and harder to accept changes over time.

Perhaps if you give me more solutions I can be more helpfull to you.
0
 
LVL 7

Expert Comment

by:Igor Bazarny
ID: 6912952
Hi,

> What should I do so that in the calling program
> I can wait till the thread in the listener program is
> done and I get the currect result

If you need such a synchronous result, why do you need different threads at all? You are going to block calling thread until working thread completes anyway, don't you? If so, I don't see much difference from single-threaded model (except of synchronization mess).

Igor

0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6913416
ok

I expand on the other thread
because there might be a delay factor when the user
expands a selected node.

In that case he can do something else in the GUI while the node is getting expanded.

This works fine

My problem arises because I have made the Tree drag enabled

now when the user tries to drag a node I want to
get all the child nodes by firing
 tree.fireTreeExpanded(path);

 public boolean isStartDragOk(DragGestureEvent e)
    {
        if(node.getAllowsChildren())
             {
               tree.fireTreeExpanded(path);
               System.out.println("children" + node.getChildren());
 
             }
 

    }

The problem is this method returns before the other
thread is done expanding so I never get the child nodes
which is obvious



I am totally confused because when the user drags a node
I want all the child nodes to be added in the transferable
But to get the child nodes I have to fire the
TreeExpandedListener which is in a different thread


What Could be the best design strategy here?

PLEASE HELP?



0
 
LVL 9

Expert Comment

by:Ovi
ID: 6915001
It sounds to me that is a stupid implementation of JTree maded by Sun team if you have right. Normaly when you access a node in any way you already have it's children, since every node keeps reference to them. Are you sure you are right ? Do you use DefaultTreeNode ?


0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6915485
Well I have added the TreeExpansionListener

So in usual case only when I fire the TreeExpanded event
the listener will go and get the child nodes

The child nodes get added to the parent node at the run time when the user clicks on the node and tries to expand the node

So this has nothing to do with JTree.It is how the
code has been implemented

Because each child node in turn may be huge and there
is no sense in adding these child nodes at the compile time


0
 
LVL 7

Accepted Solution

by:
Igor Bazarny earned 50 total points
ID: 6915548
Hi,
Would it be to slow to load one extra level in advance? When you have your root collapsed, all root children should be filled, but their children could be filled later, when root node expanded.

Regards,
Igor Bazarny,
Brainbench MVP for Java 1
www.brainbench.com
0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6919453
Hi bazarny,

How would the solution work for multiple levels

for example

Switch
 --emc
     --JBOD
         ---slice 1
         ---slice 2  
--hitachi
    --JBOD
         ---slice 1
         ---slice 2  

So even if I load the tree like this

Switch
 -- emc
 ---hitachi

now if I do expand path on emc it will only give me

Switch
 --emc
     --JBOD

 I cannot get slice 1 and slice 2

I have given up on finding a good solution.Please heeeeelp

0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6956151
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20180059.html
http://www.experts-exchange.com/questions/Q.20221686.html
http://www.experts-exchange.com/questions/Q.20234788.html
http://www.experts-exchange.com/questions/Q.20246190.html
http://www.experts-exchange.com/questions/Q.20256943.html
http://www.experts-exchange.com/questions/Q.20257803.html
http://www.experts-exchange.com/questions/Q.20257760.html
http://www.experts-exchange.com/questions/Q.20260496.html
http://www.experts-exchange.com/questions/Q.20263573.html
http://www.experts-exchange.com/questions/Q.20263541.html
http://www.experts-exchange.com/questions/Q.20266174.html
http://www.experts-exchange.com/questions/Q.20283765.html
http://www.experts-exchange.com/questions/Q.20288327.html
http://www.experts-exchange.com/questions/Q.20291180.html
http://www.experts-exchange.com/questions/Q.20291602.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20155817.html
http://www.experts-exchange.com/questions/Q.20169826.html

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations if this item remains inactive another seven (7) days.  If you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed here -> http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange
0
 
LVL 7

Expert Comment

by:Igor Bazarny
ID: 6957469
Hi,

It seems I missed the last comment. It's my fault that question still not answered.

Suggestion is following:

You need special TreeModel/TreeNode implementation. TreeNode doesn't fill it's children upon creation. Instead, it fills child list on the first call to getChildCount(), getAllowsChildren(), isLeaf(). At leas one of this methods will be called during the node rendering.

So, when whole tree is collapsed and only root is rendered, all root children are loaded. When user clicks on [+] to expand the root node, root children are rendered, and rendering triggers the loading of their children. When one of the already visible nodes expanded, all child nodes of that node load their children, preparing themselveds for expansion.

Regards,
Igor Bazarny,
Brainbench MVP for Java 1

0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6960546
Hi I have implemented a solution similiar to
bazarmy's solution but I would Have still
hoped for some better workaround

Thanks a ton though for all your help
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now