我想使用java的fork join模型来实现双音排序。所以这里是排序器的代码
import java.util.concurrent.RecursiveAction;
public class BitonicSortTask extends RecursiveAction
{
private final int array[];
private final int low;
private final int high;
private final int dir;
public BitonicSortTask(int array[],int low,int high,int dir)
{
this.array = array;
this.low = low;
this.high = high;
this.dir= dir;
}
@Override
protected void compute()
{
if(high>1)
{
int temp = high/2;
BitonicSortTask left = new BitonicSortTask(array, low, temp,1);
BitonicSortTask right = new BitonicSortTask(array, temp+1,high,0);
invokeAll(left, right);
BitonicMerge(array, low, high, dir);
}
}
private void BitonicMerge(int[] array,int low,int high,int dir)
{
if(high>1)
{
int temp = high/2;
for (int i=low; i<low+temp; i++)
compAndSwap(array,i, i+temp, dir);
BitonicMerge(array, low, temp, dir);
BitonicMerge(array, temp+1, high, dir);
}
}
private void compAndSwap(int a[],int i,int j,int dir)
{
if ( (a[i] > a[j] && dir == 1)||(a[i] < a[j] && dir == 0))
{
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
和主要(测试类)
import java.util.Arrays;
import java.util.concurrent.ForkJoinPool;
public class BitonicSortTest
{
public static void main(String[] args)
{
int l=0;
int h=999;
int a[] = new int[10];
for(int i=0; i<10; i++)
{
a[i] = (int) (i*Math.round(Math.random()));
}
BitonicSortTask task = new BitonicSortTask(a, l, h, 1);
ForkJoinPool fjp= new ForkJoinPool();
fjp.invoke(task);
System.out.println(Arrays.toString(a));
}
}
但是每当我运行这段代码时,我都会得到
Exception in thread "main" java.lang.NoClassDefFoundError: Could not
initialize class java.util.concurrent.locks.AbstractQueuedSynchronizer$Node
能否请您告诉我造成这种情况的原因以及如何解决。