• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

related to thread

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
sanjay_thakur
Asked:
sanjay_thakur
  • 5
  • 3
  • 2
  • +2
1 Solution
 
rashidkamranbsCommented:
a join() method call to that thread from the calling program could be helpful ..

0
 
sanjay_thakurAuthor Commented:
How do I find the other thread?
0
 
OviCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Igor BazarnyCommented:
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
 
sanjay_thakurAuthor Commented:
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
 
OviCommented:
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
 
sanjay_thakurAuthor Commented:
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
 
Igor BazarnyCommented:
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
 
sanjay_thakurAuthor Commented:
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
 
MoondancerCommented:
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
 
Igor BazarnyCommented:
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
 
sanjay_thakurAuthor Commented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now