I have a simple java parallel algorithm implemented using Spark. But I am not sure how I can run it on Google Dataproc cluster. I found a lot of resources online that uses python or scala but not enough for java. here is the code
public class Prime {
List<Integer> primes = new ArrayList<>();
//Method to calculate and count the prime numbers
public void countPrime(int n){
for (int i = 2; i < n; i++){
boolean isPrime = true;
//check if the number is prime or not
for (int j = 2; j < i; j++){
if (i % j == 0){
isPrime = false;
break; // exit the inner for loop
}
}
//add the primes into the List
if (isPrime){
primes.add(i);
}
}
}
//Main method to run the program
public static void main(String[]args){
//creating javaSparkContext object
SparkConf conf = new SparkConf().setAppName("haha").setMaster("local");
JavaSparkContext sc = new JavaSparkContext(conf);
//new prime object
Prime prime = new Prime();
prime.countPrime(100000);
//parallelize the collection
JavaRDD<Integer> rdd = sc.parallelize(prime.primes , 4);
long count = rdd.filter(e -> e == 2|| e % 2 != 0).count();
}
}