Created
October 25, 2012 19:10
-
-
Save gustavopinto/3954760 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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