Testing multithreading (#9193)
This commit is contained in:
committed by
GitHub
parent
068523493b
commit
57519b9dae
+22
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.concurrent;
|
||||
|
||||
public class MyCounter {
|
||||
|
||||
private int count;
|
||||
|
||||
public void increment() {
|
||||
int temp = count;
|
||||
count = temp + 1;
|
||||
}
|
||||
|
||||
public synchronized void incrementWithWait() throws InterruptedException {
|
||||
int temp = count;
|
||||
wait(100);
|
||||
count = temp + 1;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user