Computing the correlation of an analyzed stock ticker I have an enum of stock tickers, then from the database I get details for an analysed ticker (stock). In the loop, I compare the details of the analysed ticker to details of the rest of tickers, compute the correlation, then add it to the treeSet.

This is my first time using multithreading and I wanted the method executed in a shorter time. I'm not sure about this solution. Could you review my code and judge it?

This is my service:

@Service public class StatisticService{

    @Inject
    private StockDetailsRepository stockDetailsRepository;

    @Inject
    private StockRepository stockRepository;

    private List&lt;GpwStockTicker&gt; tickersWithOutOneAnalysed;
    private TreeSet&lt;StockStatistic&gt; correlationTreeSet;
    private double [] closePricesAnalysed;
    private int size;
    private PearsonsCorrelation pearsonsCorrelation;

    public TreeSet&lt;StockStatistic&gt; computePearsonCorrelation(Stock stock, int size) {
        this.size = size;
        long start = System.currentTimeMillis();
        correlationTreeSet = new TreeSet&lt;&gt;();
        pearsonsCorrelation = new PearsonsCorrelation();
        GpwStockTicker mainTicker = stock.getTicker();
        List&lt;StockDetails&gt; stockDetailsAnalysed = getContent(mainTicker, size);
        closePricesAnalysed = getClosePrices(stockDetailsAnalysed);
        EnumSet&lt;GpwStockTicker&gt; tickers = complementOf(EnumSet.of(mainTicker));
        tickersWithOutOneAnalysed = new ArrayList&lt;GpwStockTicker&gt;(tickers);

        Thread threadOne = new Thread(new Runnable() {
            public void run() {
                firstPartTickers();
            }
        });

        Thread threadTwo = new Thread(new Runnable() {
            public void run() {
                secondPartTickers();
            }
        });

        threadOne.start();
        threadTwo.start();

        try {
            threadOne.join();
            threadTwo.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        long end = System.currentTimeMillis();
        System.out.println("Time of method (s): "+ (end-start) / 1000.0);
        return correlationTreeSet;
    }

    private void firstPartTickers() {
        for(int i = 0; i&lt; tickersWithOutOneAnalysed.size()/2; i++) {
            calculateCorrelation(i);
        };
    }

    private void secondPartTickers() {
        for(int i = tickersWithOutOneAnalysed.size()/2; i&lt; tickersWithOutOneAnalysed.size(); i++) {
            calculateCorrelation(i);
        };
    }

    private void calculateCorrelation(int indexOfTicker) {
        GpwStockTicker ticker = GpwStockTicker.valueOf(tickersWithOutOneAnalysed.get(indexOfTicker).name());
        double [] closePricesToCompare = getClosePrices(getContent(ticker, size));
        Double correlation  = pearsonsCorrelation.correlation(closePricesAnalysed, closePricesToCompare);
        StockStatistic stockCorrelation = new StockStatistic(correlation, ticker);
        correlationTreeSet.add(stockCorrelation);
    }

    private List&lt;StockDetails&gt; getContent(GpwStockTicker ticker, int size) {
        return stockDetailsRepository.findByStockTickerOrderByDateDesc(ticker, new PageRequest(1, size)).getContent();
    }

    private double[] getClosePrices(List&lt;StockDetails&gt; stockDetails) {
        double[] closePrices = new double[stockDetails.size()];

        int idx = 0;
        for(StockDetails stds: stockDetails){
            closePrices[idx++] = stds.getClosePrice().doubleValue();
        }

        return closePrices;
    } 
}


The main goal was achieved: the time before multithreading was 77.277 sec and after was 43.534 sec. But I would like to know if my way of thinking was good.
private void firstPartTickers() {
        for(int i = 0; i&lt; tickersWithOutOneAnalysed.size()/2; i++) {
            calculateCorrelation(i);
        };
    }

    private void secondPartTickers() {
        for(int i = tickersWithOutOneAnalysed.size()/2; i&lt; tickersWithOutOneAnalysed.size(); i++) {
            calculateCorrelation(i);
        };
    }



You have two almost identical methods.  Is this really necessary?  Consider the following method:  

    private void calculateTickers(int start, int increment) {
        for (int i = start; i &lt; tickersWithOutOneAnalysed.size(); i += increment) {
            calculateCorrelation(i);
        }
    }


Note that I also removed the unnecessary ; after the for loop.  

Now you can just call 

                calculateTickers(0, 2);
                calculateTickers(1, 2);


instead of 


                firstPartTickers();
                secondPartTickers();



And if you later wanted to do a third thread, you could say 

                calculateTickers(0, 3);
                calculateTickers(1, 3);
                calculateTickers(2, 3);