Skip to content

Instantly share code, notes, and snippets.

@gustavopinto
Created October 25, 2012 19:10
Show Gist options
  • Select an option

  • Save gustavopinto/3954760 to your computer and use it in GitHub Desktop.

Select an option

Save gustavopinto/3954760 to your computer and use it in GitHub Desktop.
public class TesteLockWatts {
private Contador contador = new Contador();
public void testar() {
for (int i = 0; i < 1000; i++) {
new Thread() {
public void run() {
for (int j = 0; j < 100000; j++) {
contador.increment();
}
}
}.start();
}
contador.total();
}
public static void main(String args[]) throws InterruptedException {
long inicio = System.currentTimeMillis();
new TesteLockWatts().testar();
long fim = System.currentTimeMillis();
System.out.println(fim - inicio);
}
}
class Contador {
private int counter;
public void increment() {
counter++;
}
public int total() {
return counter;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment