Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

james walder

Greenhorn
+ Follow
since Mar 17, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by james walder

MulitThreads Problem
i am trying to write the code for a multithread where it can sort both numeric and string data then sort the data in an array were pairs of arrays are compared and swapped if out of order any help would be great. the code so far is as follows

public class MultiThread implements Runnable{
public int countDown=4;
public int threadNumber;
private static int threadCount=0;
public int[] myarray = {3,1,4,2};
public MultiThread()
{
threadNumber =++ threadCount;
System.out.println("Making" + threadNumber);
}
public void swap(int[] myarray,int a,int b)
{
int tmp;
tmp = a;
a = b;
b = tmp;
System.out.println(a +" "+ b);
return;
}
public void run()
{
while(true)
{
System.out.println("Thread"+
threadNumber+"("+ countDown +")");

while (true){
try

{
if (myarray[0] <= myarray[1] && myarray[1] <= myarray[2] && myarray[2] <= myarray[3]);

Thread.yield();
Thread.sleep(1000);
if (myarray[0] > myarray[1])
{
swap(myarray,myarray[0],myarray[1]);
}
if (myarray[1] > myarray[2])
{
swap(myarray,myarray[1],myarray[2]);
}
if (myarray[2] > myarray[3])
{
swap(myarray,myarray[2],myarray[3]);
}
System.out.println(myarray[0] +" "+ myarray[1] +" "+ myarray[2] +" "+ myarray[3]);
}
catch (InterruptedException e){}
//if (myarray[0] <= myarray[1] && myarray[1] <= myarray[2] && myarray[2] <= myarray[3]);
// {
// return;
// }
if(-- countDown == 0 )
return;
}
}
}
public static void main ( String args[] )
{
for(int i =0; i<4; i++)
{
MultiThread mT = new MultiThread();
Thread t = new Thread(mT);
t.start();
}
System.out.println("All Threads Started");
}

}
[ March 18, 2004: Message edited by: james walder ]
[ March 18, 2004: Message edited by: james walder ]