Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 2f80903e authored by Gabriel Landais's avatar Gabriel Landais
Browse files

Prep for proxy load tests

git-svn-id: https://scm.gforge.inria.fr/authscm/ycadoret/svn/gazelle/Maven/gazelle-proxy/trunk@27178 356b4b1a-1d2b-0410-8bf1-ffa24008f01e
parent 5cab5523
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<parent>
<artifactId>gazelle-proxy</artifactId>
<groupId>net.ihe.gazelle.proxy</groupId>
<version>1.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>net.ihe.gazelle.proxy</groupId>
<artifactId>gazelle-proxy-loadtests</artifactId>
<version>1.2-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
package org.gazelle.proxy.loadtests;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
public class App {
public static void main(String[] args) throws InterruptedException, ExecutionException {
ThreadPoolExecutor threadPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(12);
List<Future<String>> futures = new ArrayList<Future<String>>();
for (int i = 0; i < 200; i++) {
final int j = i;
Callable<String> task = new Callable<String>() {
@Override
public String call() throws Exception {
System.out.println("Called " + j);
Thread.sleep(500 + Math.round(Math.random() * 500));
System.out.println("Done " + j);
return "toto" + j;
}
};
Future<String> future = threadPool.submit(task);
futures.add(future);
}
while (threadPool.getQueue().size() > 0) {
Thread.sleep(1000);
}
boolean allFinished = false;
while (!allFinished) {
allFinished = true;
for (Future<String> future : futures) {
allFinished = allFinished && future.isDone();
}
if (!allFinished) {
Thread.sleep(1000);
}
}
for (Future<String> future : futures) {
System.out.println(future.get());
}
threadPool.shutdown();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment