Results 1 to 6 of 6
  1. #1
    Ebodee is offline Member
    Join Date
    Sep 2009
    Posts
    4
    Rep Power
    0

    Default Thread concurrency .. What am I missing?

    I have spent the better part of the day, albeit fairly diverted on the topic of multithreading and trying to get my threads to work concurrently. They appear to operate in much the same way a normal sequenced program runs.

    What am I doing wrong? I am using a runnable interface, normal thread creation, and using sleep timers but my novice level is getting me nowhere.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    What am I doing wrong?
    It could be an extra semi-colon on line 42, a call to run() instead of start(), over-use of join(), but for me, then main thing that you're doing wrong is that you're not showing us any of your code. That's about the best most of us can do with the info provided.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,535
    Blog Entries
    7
    Rep Power
    20

    Default

    ... and sleeping Threads are also a concurrency killer.

    kind regards,

    Jos

  4. #4
    Ebodee is offline Member
    Join Date
    Sep 2009
    Posts
    4
    Rep Power
    0

    Default

    Ok, fair point, not much help I can receive without code. Some background. I am just starting to learn multithreading so tinkering is what I have done since the Java course I am taking this semester is algorithms but always great opportunity to use a project to learn something new.

    My implementation is through the Runnable interface and I submit my code here with the sleep() lines removed per the previous suggestion.



    Java Code:
    public interface Runnable {
    
        public abstract void run() ;
    
    }
    Java Code:
     public void run()
        {
            int count = 10,enQueueCounter = 1;
    
            do
            {
                int nextPoisson = linkedList.Poisson(expectedValue);
                for (int i = 0; i < nextPoisson; i++)
                {
                    linkedList.enQueue("Manny" + enQueueCounter, 0);  // enQueue the node
                    enQueueCounter += 1;
                    count--;
                }
    
                linkedList.setTime();        // set the wait time
    
                int temp = linkedList.getTime();
                avgWaitTime = temp / enQueueCounter;
                System.out.println("Average wait time is: " + avgWaitTime + " (s)");
                          
            }
            while(count > 0);
    
            System.out.println(enQueueCounter - 1 + " person queued");
            linkedList.list();
        }
    Java Code:
     public void run()
       {   
            for (seconds = 0; seconds < 5; seconds++)
            {
                System.out.println(toString());
    
            }
      
           
       }
    Java Code:
    public static void main(String[] args){
    
            MyList linkedList = new MyList();
    
            Arrivals newArrivals = new Arrivals("Arrivals", 0.5);
    
            Server newServer = new Server("Server");
    
            newArrivals.getObject(linkedList); // reference passing
    
            newArrivals.run();
            newServer.run();
    }
    I may not even be implementing mutilthreading. The threads are running sequentially and here is my problem.
    Last edited by Ebodee; 01-31-2010 at 07:25 PM.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,535
    Blog Entries
    7
    Rep Power
    20

    Default

    I don't see any Thread objects in your program code ...

    kind regards,

    Jos

  6. #6
    Ebodee is offline Member
    Join Date
    Sep 2009
    Posts
    4
    Rep Power
    0

    Default

    I decided to use the Executor server and run my threads through that also using the default Runnable interface instead of supplying one.

Similar Threads

  1. GUI Concurrency Problems
    By jkhamler in forum Threads and Synchronization
    Replies: 18
    Last Post: 01-20-2010, 03:40 PM
  2. IProgessMonitor missing in 3.4?
    By aznboarder in forum Eclipse
    Replies: 1
    Last Post: 03-19-2009, 11:29 PM
  3. Concurrency system, and threads.
    By scarymovie in forum New To Java
    Replies: 2
    Last Post: 03-05-2009, 02:20 AM
  4. concurrency question
    By diggitydoggz in forum New To Java
    Replies: 4
    Last Post: 01-17-2009, 03:48 AM
  5. Explanation bout threading and concurrency?
    By cruxblack in forum New To Java
    Replies: 1
    Last Post: 08-10-2007, 10:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •