Back to project page androidtestdebug.
The source code is released under:
MIT License
If you think the Android project androidtestdebug listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
// // ?????/*from w w w . j av a 2s. c om*/ // javac -encoding UTF8 RaceConditionFix.java // public class RaceConditionFix { private static int _sharedCounter = 0; private synchronized static void dekker1() { _sharedCounter++; } private synchronized static void dekker2() { _sharedCounter++; } public static void main(String[] args) throws Exception { if ( args.length != 1 ) { System.out.println("????: java RaceCondition <????>"); return; } final int loopCount = Integer.parseInt(args[0]); Thread thread1 = new Thread(new Runnable() { public void run() { for ( int i = 0; i < loopCount; ++i ) { dekker1(); } } }); Thread thread2 = new Thread(new Runnable() { public void run() { for ( int i = 0; i < loopCount; ++i ) { dekker2(); } } }); thread1.start(); thread2.start(); thread1.join(); thread2.join(); int expected_sum = 2 * loopCount; if ( _sharedCounter != expected_sum ) { System.out.println( String.format("???????: ???? $1%d ???????? $2%d", _sharedCounter, expected_sum)); } } }