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 2 of 2

Thread: Thread Question

  1. #1
    Member
    Join Date
    Dec 2010
    Posts
    69
    My Mood
    Busy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Thread Question

    How would I go about loading another separate classes LinkedList with a number in my current class? I want to retrieve the number that is getting "pulled" (via the .pullOrder in this Run method) and load it into a linkedList called printerQueue in another class (called OrderQueue).
    public class OrderHandler extends Thread	{
     
        private OrderQueue orderQueue;
     
     
        public OrderHandler(OrderQueue orderQueue)
        {	this.orderQueue = orderQueue;
     
        }
     
        public void run()	{
     
            Order order;
            while (true)	{
                    order = orderQueue.pullOrder();     // get next available order
                    OrderQueue.printerQueue = order;
                    System.out.println("\t\t\t " + order.toString() + "    " + this.getName());
     
                    try
                    {	Thread.sleep(2000);		}             // delay two seconds
     
                    catch (InterruptedException e) {}   	    // ignore interruptions
     
            }	// end while
     
        }	// end run method
     
    }	// end OrderHandler class


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

    Default Re: Thread Question

    Create a field and pass that linked list to your OrderHandler constructor (I can't remember whether OrderHandler is multi-thread safe, you'll need to check). Accessing that linked list works the same as accessing any other field.

Similar Threads

  1. THE THREAD SOLVER
    By javapenguin in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 16th, 2010, 09:49 PM
  2. thread pool question
    By balexios in forum Threads
    Replies: 3
    Last Post: October 24th, 2010, 03:47 AM
  3. Thread to EDT
    By Asido in forum Threads
    Replies: 3
    Last Post: October 15th, 2010, 01:13 PM
  4. Is thread the best option?
    By 256mxr in forum Threads
    Replies: 1
    Last Post: May 22nd, 2010, 08:24 PM
  5. Thread Sleep, Timer, Button Question
    By tabutcher in forum Java Theory & Questions
    Replies: 1
    Last Post: May 1st, 2010, 02:54 AM