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);
}
}
}
}
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!