Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Question on dependency execution

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Question on dependency execution

    Hi,
    I'm completely new to java. I'm trying the tackle this following scenario. For e.g. I've a list of “Tasks” and their dependencies. E.g. Task D depends on (Task A and Task B) , Task A depends on Task B, Task B depends on Task C.
    I'm trying to write a program to print out the sequence of these tasks (For example, using the case above, it should be C, B, A, D).
    1. What is the best way to approach this ?
    2. What possible ways I can test this design?
    3. How can I make sure that there's no circular dependency?
    Any pointers will be highly appreciated.
    -Thanks


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Question on dependency execution

    You can use a graph/map data structure with nodes being tasks and the paths being the dependencies. If from any node you can get back to the starting node, you will have circular dependencies (some kind of variation on Dijkstra's Algorithm should work).

    If you cannot, then there are no circular dependencies. At this point just pick a node and try to recursively resolve it's dependencies first (mark them off as they get done), then resolve that node and mark it as being done.. You're done when all jobs have been marked done.

    edit: A second alternative to resolving tasks is via a Priority Queue. However, I think to use a Priority Queue you must first check to make sure there are no circular dependencies first.
    Last edited by helloworld922; May 1st, 2010 at 09:48 PM.

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    back2grave (May 2nd, 2010)

  4. #3
    Junior Member
    Join Date
    May 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Question on dependency execution

    Thanks helloworld...I was looking into digraphs algorithm....will explore your suggestion and post my findings

Similar Threads

  1. Java GUi program Execution
    By Rajan in forum AWT / Java Swing
    Replies: 2
    Last Post: April 19th, 2010, 08:48 PM
  2. program execution with warnings
    By prince joseph in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 28th, 2010, 03:53 PM
  3. Not Looping? (do - while) bad execution!
    By chronoz13 in forum Loops & Control Statements
    Replies: 1
    Last Post: November 23rd, 2009, 08:51 PM
  4. Build/dependency management software
    By Json in forum The Cafe
    Replies: 0
    Last Post: August 19th, 2009, 03:03 AM