This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SyncTest { | |
| Boolean lock1 = true; | |
| public void testr() { | |
| String name = Thread.currentThread().getName(); | |
| synchronized(lock1) { | |
| lock1 = !lock1; | |
| long time1 = System.currentTimeMillis(); | |
| System.out.println("bef: name:" + name + ", time: " + time1 + ", lock1:" + lock1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SyncTest { | |
| Boolean lock1 = true; | |
| public void testr() { | |
| String name = Thread.currentThread().getName(); | |
| synchronized(lock1) { | |
| long time1 = System.currentTimeMillis(); | |
| System.out.println("bef: name:" + name + ", time: " + time1 + ", lock1:" + lock1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SyncTest { | |
| Character lock1 = 2; | |
| //Character lock1 = 200; //vs using this for lock. | |
| public void testr() { | |
| String name = Thread.currentThread().getName(); | |
| synchronized(lock1) { | |
| long time1 = System.currentTimeMillis(); | |
| System.out.println("bef: name:" + name + ", time: " + time1 + ", lock1:" + lock1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SyncTest { | |
| Integer lock1 = 2; | |
| //Integer lock1 = 200; //vs using. | |
| public void testr() { | |
| String name = Thread.currentThread().getName(); | |
| synchronized(lock1) { | |
| long time1 = System.currentTimeMillis(); | |
| System.out.println("bef: name:" + name + ", time: " + time1 + ", lock1:" + lock1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SyncTest { | |
| Boolean lock1 = false; | |
| public void testr() { | |
| String name = Thread.currentThread().getName(); | |
| synchronized(lock1) { | |
| long time1 = System.currentTimeMillis(); | |
| System.out.println("bef: name:" + name + ", time: " + time1 + ", lock1:" + lock1); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package io.zapscanner.admin; | |
| public class SP14 { | |
| static class R extends Thread { | |
| @Override | |
| public synchronized void start() { | |
| System.out.println("in start, t:" + Thread.currentThread().getName()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SP13 { | |
| static class R extends Thread { | |
| @Override | |
| public synchronized void start() { | |
| System.out.println("in start, t:" + Thread.currentThread().getName()); | |
| } | |
| @Override | |
| public void run() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SP11 { | |
| public synchronized SP11() { | |
| } | |
| public static void main(String[] args) { | |
| System.out.printf("Hello World! Synchronized Constructor!"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SP4 { | |
| public synchronized void func1() { | |
| System.out.println("func1"); | |
| func2(); | |
| } | |
| public synchronized void func2() { | |
| System.out.println("func2"); | |
| func3(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SP10 { | |
| public static void main(String[] args) { | |
| Thread t = new Thread(); | |
| t.start(); | |
| t.start(); | |
| } | |
| } |