Testing multithreading (#9193)
This commit is contained in:
committed by
GitHub
parent
0a620333df
commit
6370f2ae4a
@@ -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