blob: a073a959181458ea49549f108932e8e34120194f [file] [log] [blame]
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17public class Main {
18 public static void main(String[] args) {
19 $opt$StaticSynchronizedMethod();
20 new Main().$opt$InstanceSynchronizedMethod();
21 $opt$SynchronizedBlock();
22 new Main().$opt$DoubleInstanceSynchronized();
23 $opt$DoubleStaticSynchronized();
24 }
25
26 public static synchronized void $opt$StaticSynchronizedMethod() {
27 System.out.println("In static method");
28 }
29
30 public synchronized void $opt$InstanceSynchronizedMethod() {
31 System.out.println("In instance method");
32 }
33
34 public static void $opt$SynchronizedBlock() {
35 Object o = new Object();
36 synchronized(o) {
37 System.out.println("In synchronized block");
38 }
39 }
40
41 public synchronized void $opt$DoubleInstanceSynchronized() {
42 synchronized (this) {
43 System.out.println("In second instance method");
44 }
45 }
46
47 public synchronized static void $opt$DoubleStaticSynchronized() {
48 synchronized (Main.class) {
49 System.out.println("In second static method");
50 }
51 }
52}