Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Harley Evans   on Jun 13 In Java Category.

  
Question Answered By: Nagaraju Iyaner   on Jun 13

try putting Thread.yield() in each of your loops as in:

class x extends Thread
{
public void  run()
{
for(int i =0;i<test.count;i++)
{
System.out.println("x");
Thread.yield();
}
}
}
class y extends Thread
{
public void run()
{
for(int i =0;i<test.count;i++)
{
System.out.println("y");
Thread.yield();
}
}
}

public class  test
{
public static final int count = 4;
public static void main(String args[])
{
new x().start();
new y().start();
}
}


result:
x
x
y
x
y
x
y
y

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on java thread programming Or get search suggestion and latest updates.


Tagged: