Skip to content

Commit b386a93

Browse files
committed
refactor: use %n in printf format instead of \n
1 parent eebc7a8 commit b386a93

File tree

7 files changed

+10
-12
lines changed

7 files changed

+10
-12
lines changed

src/main/java/fucking/concurrency/demo/HashMapHangDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static void main(String[] args) {
3030

3131
// If the hashmap occurs hang problem, the following output will not appear again.
3232
// On my dev machine, this problem is easily observed in the first round.
33-
System.out.printf("Got key %s in round %s\n", j, i);
33+
System.out.printf("Got key %s in round %s%n", j, i);
3434
}
3535
}
3636
}

src/main/java/fucking/concurrency/demo/InconsistentReadDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void run() {
3535
c++;
3636
// On my dev machine,
3737
// a batch of inconsistent reads can be observed when the process starts
38-
System.err.printf("Fuck! Got inconsistent read!! check time=%s, happen time=%s(%s%%), 1=%s, 2=%s\n",
38+
System.err.printf("Fuck! Got inconsistent read!! check time=%s, happen time=%s(%s%%), 1=%s, 2=%s%n",
3939
i + 1, c, (float) c / (i + 1) * 100, c1, c2);
4040
}
4141
}

src/main/java/fucking/concurrency/demo/InvalidCombinationStateDemo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public void run() {
3333
int i2 = state2;
3434
if (i1 * 2 != i2) {
3535
c++;
36-
System.err.printf("Fuck! Got invalid CombinationStat!! check time=%s, happen time=%s(%s%%), count value=%s|%s\n",
36+
System.err.printf("Fuck! Got invalid CombinationStat!! check time=%s, happen time=%s(%s%%), count value=%s|%s%n",
3737
i + 1, c, (float) c / (i + 1) * 100, i1, i2);
3838
} else {
3939
// if remove blew output,
4040
// the probability of invalid combination on my dev machine goes from ~5% to ~0.1%
41-
System.out.printf("Emm... %s|%s\n", i1, i2);
41+
System.out.printf("Emm... %s|%s%n", i1, i2);
4242
}
4343
}
4444
}

src/main/java/fucking/concurrency/demo/InvalidLongDemo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public void run() {
3737
long low = l & 0xFFFFFFFFL;
3838
if (high != low) {
3939
c++;
40-
System.err.printf("Fuck! Got invalid long!! check time=%s, happen time=%s(%s%%), count value=%s|%s\n",
40+
System.err.printf("Fuck! Got invalid long!! check time=%s, happen time=%s(%s%%), count value=%s|%s%n",
4141
i + 1, c, (float) c / (i + 1) * 100, high, low);
4242
} else {
4343
// If remove this output, invalid long is not observed on my dev machine
44-
System.out.printf("Emm... %s|%s\n", high, low);
44+
System.out.printf("Emm... %s|%s%n", high, low);
4545
}
4646
}
4747
}

src/main/java/fucking/concurrency/demo/ReentrantLockLivelockDemo.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public static void main(String[] args) throws Exception {
1818
thread2.start();
1919
}
2020

21-
@SuppressWarnings("InfiniteLoopStatement")
2221
private static void concurrencyCheckTask1() {
2322
System.out.println("Started concurrency check task 1");
2423
int counter = 0;
@@ -44,12 +43,11 @@ private static void concurrencyCheckTask1() {
4443
break;
4544
}
4645

47-
System.err.printf("Fuck! No meaningful work done in %s iterations of task 1.\n", counter);
46+
System.err.printf("Fuck! No meaningful work done in %s iterations of task 1.%n", counter);
4847
lock2.unlock();
4948
lock1.unlock();
5049
}
5150

52-
@SuppressWarnings("InfiniteLoopStatement")
5351
private static void concurrencyCheckTask2() {
5452
System.out.println("Started concurrency check task 2");
5553

@@ -75,7 +73,7 @@ private static void concurrencyCheckTask2() {
7573
break;
7674
}
7775

78-
System.err.printf("Fuck! No meaningful work done in %s iterations of task 2.\n", counter);
76+
System.err.printf("Fuck! No meaningful work done in %s iterations of task 2.%n", counter);
7977
lock2.unlock();
8078
lock1.unlock();
8179
}

src/main/java/fucking/concurrency/demo/SynchronizationOnMutableFieldDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void main(String[] args) throws Exception {
3333
// On my development machine, it's almost must occur!
3434
// Simple and safe solution:
3535
// final List field and use concurrency-safe List, such as CopyOnWriteArrayList
36-
System.err.printf("Fuck! Lost update on mutable field! actual %s expected %s.\n", actualSize, expectedSize);
36+
System.err.printf("Fuck! Lost update on mutable field! actual %s expected %s.%n", actualSize, expectedSize);
3737
} else {
3838
System.out.println("Emm... Got right answer!!");
3939
}

src/main/java/fucking/concurrency/demo/WrongCounterDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static void main(String[] args) throws Exception {
2727
// On my dev machine, it's almost must occur!
2828
// Simple and safe solution:
2929
// use AtomicInteger
30-
System.err.printf("Fuck! Got wrong count!! actual %s, expected: %s.", actualCounter, expectedCount);
30+
System.err.printf("Fuck! Got wrong count!! actual %s, expected: %s.%n", actualCounter, expectedCount);
3131
} else {
3232
System.out.println("Wow... Got right count!");
3333
}

0 commit comments

Comments
 (0)