2018-03-19

PrimerFinder.java:

package okhttp3.benchmarks;

public class PrimeFinder implements Runnable{
    public long target;
    public long prime;
    public boolean finished = false;
    private Thread runner;
    
    PrimeFinder(long inTarget) {
        target = inTarget;
        if(runner == null) {
            runner = new Thread(this);
            runner.start();
        }
    }

    @Override
    public void run() {
        
        long numPrimes = 0;
        long candidate = 2;
        while ( numPrimes < target){
            if (isPrime(candidate)) {
                numPrimes++;
                prime = candidate;
            }
            
            candidate++;
        }
        finished = true;
    }
    
    boolean isPrime(long checkNumber) {
        
        double root = Math.sqrt(checkNumber);
        for(int i =2; i <= root;i++){
            if(checkNumber % i == 0)
                return false;
        }
        return true;
    }
    public static void main(String[] args) {
        System.out.println(new PrimeFinder(0).isPrime(97));
    }
}

PrimerThreads.java:

package okhttp3.benchmarks;

public class PrimeThreads {
    public static void main(String[] args) {
        PrimeThreads pt = new PrimeThreads(args);
        //第两百五十万个素数41161739 
        //System.out.println(new PrimeFinder(0).isPrime(41161739));
    }
    
    
    public PrimeThreads(String[] arguments){
        PrimeFinder[] finder = new PrimeFinder[arguments.length];
        for(int i = 0;i 

运行结果:

2018-03-19_第1张图片

//创建okHttpClient对象
OkHttpClient mOkHttpClient = new OkHttpClient();
//创建一个Request
final Request request = new Request.Builder()
                .url("https://github.com/hongyangAndroid")
                .build();
//new call
Call call = mOkHttpClient.newCall(request); 
//请求加入调度
call.enqueue(new Callback()
        {
            @Override
            public void onFailure(Request request, IOException e)
            {
            }

            @Override
            public void onResponse(final Response response) throws IOException
            {
                    //String htmlStr =  response.body().string();
            }
        });             



你可能感兴趣的:(2018-03-19)