Skip to content

Instantly share code, notes, and snippets.

@Dnomyar
Created April 21, 2017 07:38
Show Gist options
  • Save Dnomyar/3bb7b35c34760f212aafa32d6b284f87 to your computer and use it in GitHub Desktop.
Save Dnomyar/3bb7b35c34760f212aafa32d6b284f87 to your computer and use it in GitHub Desktop.
Concurrence test using Stream API (.parallel() method)
public class TestConcurrence {
public static void main(String[] args) {
String address = "http://localhost:8080/servicejava/serverStatefull";
System.out.println("*****************************");
final WebTarget target = AppliCliente.clientJAXRS().target(address);
final Automate automate = WebResourceFactory.newResource(Automate.class, target);
int NB_REQUEST = 1000;
final long count = Stream.iterate(0, i -> i + 1)
.limit(NB_REQUEST)
.parallel()
.map(i -> automate.initier().getNumero())
.distinct()
.count();
System.out.println(count + "/" + NB_REQUEST);
System.out.println("*****************************");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment