---
title: "线程池压测"
author: "e_e"
date: "2017-03-22T10:15:11Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2017-03-22T10:15:11Z"
id: 2364663
url: "https://e-e.iteye.com/blog/2364663"
---

public static void main(String\[] args) throws Exception {

        ExecutorService es = Executors.newFixedThreadPool(300);

 

        Callable&lt;Object&gt; cb = new Callable() {

            @Override

            public Object call() throws Exception {

                Connection conn = Neo4jUtil.getConnection();

                Statement statement = conn.createStatement();

                TimeUnit.SECONDS.sleep(1);

                Neo4jUtil.freeConnection(null, statement, conn);

                return null;

            }

        };

        List&lt;Callable&lt;Object&gt;&gt; cl = new ArrayList&lt;&gt;();

        for(int j=0;j&lt;=400;j++){

            cl.add(cb);

            j++;

        }

        es.invokeAll(cl);

    }