summaryrefslogtreecommitdiffstats
path: root/tests/features152/synchronization/Basic.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/features152/synchronization/Basic.java')
-rw-r--r--tests/features152/synchronization/Basic.java44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/features152/synchronization/Basic.java b/tests/features152/synchronization/Basic.java
new file mode 100644
index 000000000..3af3d523c
--- /dev/null
+++ b/tests/features152/synchronization/Basic.java
@@ -0,0 +1,44 @@
+// Exploring synchronization
+
+public class Basic {
+ public static void main(String[] args) {
+ Basic b = new Basic();
+
+ b.methodWithSyncBlock1();
+ b.staticMethodWithSyncBlock1();
+ b.methodWithSyncBlock2();
+ b.staticMethodWithSyncBlock2();
+ }
+
+ public void methodWithSyncBlock1() {
+ System.err.println("methodWithSyncBlock1");
+ synchronized (this) {
+ }
+ }
+
+ public void staticMethodWithSyncBlock1() {
+ System.err.println("staticMethodWithSyncBlock1");
+ synchronized (Basic.class) {
+ }
+ }
+
+ public void methodWithSyncBlock2() {
+ System.err.println("methodWithSyncBlock2");
+ synchronized (this) {
+ int i = 0;
+ while (i<100) {
+ i++;
+ }
+ }
+ }
+
+ public void staticMethodWithSyncBlock2() {
+ System.err.println("staticMethodWithSyncBlock2");
+ synchronized (Basic.class) {
+ int i = 0;
+ while (i<100) {
+ i++;
+ }
+ }
+ }
+}