Skip to content

Instantly share code, notes, and snippets.

@liuchang0812
Created January 12, 2014 08:18
Show Gist options
  • Save liuchang0812/8382221 to your computer and use it in GitHub Desktop.
Save liuchang0812/8382221 to your computer and use it in GitHub Desktop.
/* 声明一个rmi接口
package exam;
import java.rmi.*;
public interface primeinterface extends Remote {
public boolean isPrime(int num) throws RemoteException;
}
/* 实现这个接口的RMI对象
package exam;
import java.rmi.*;
import java.rmi.server.*;
public class rmiserver extends UnicastRemoteObject implements primeinterface
{
protected rmiserver() throws RemoteException {
super();
// TODO Auto-generated constructor stub
}
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public boolean isPrime(int num) throws RemoteException {
for(int i = 2;i*i <= num;i ++)
if ( num % i == 0)
return false;
return true;
}
}
然后,我们就可以调用这个rmi接口来判断一个数是不是质数了,分布式的计算1000以内的质数
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment