CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2014
    Posts
    1

    java multi threading problems

    Hi Guys!

    I new to programming, and I've been trying to study threads in java. I've made this program and I want it to write out 'hi' 'my name is Rodger' in an infinite loop. As you guys can see I have 2 threads in this program and I want them to run in sync . However I've had major issues trying to debug my program, I think I'm really close, but I'm not sure where I've gone wrong!

    public class MyThread{

    public static void main (String args[])
    {

    String a ="Hi";
    String b= "My name is Rodger";
    }


    class t1 extends Thread
    {

    public void run(){

    boolean hi= true;
    while (hi==true);

    }

    System.out.println(a);

    }




    class t2 extends Thread
    {

    public void run(){

    boolean meh= true;

    while (meh==true);{

    System.out.println(b);
    }

    }
    }


    }

  2. #2
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: java multi threading problems

    1. Wrong forum. This is a C++ forum.
    2. You must create two thread objects and also start them, otherwise nothing will happen.
    3. Your code is also incorrectly written and will not compile - maybe try to fix that first!
    Nobody cares how it works as long as it works

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured