Skip to content

Instantly share code, notes, and snippets.

View phoenix24's full-sized avatar
🎯
Focusing

Chaitanya Sharma phoenix24

🎯
Focusing
View GitHub Profile
@phoenix24
phoenix24 / SyncTest.java
Created January 17, 2019 13:09
sync experiment 5
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);
@phoenix24
phoenix24 / SyncTest.java
Created January 17, 2019 13:09
sync experiment 4
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);
@phoenix24
phoenix24 / SyncTest.java
Created January 17, 2019 13:04
sync experiment 3
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);
@phoenix24
phoenix24 / SyncTest.java
Created January 17, 2019 13:03
sync experiment 2
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);
@phoenix24
phoenix24 / SyncTest.java
Created January 17, 2019 13:01
sync experiment 1
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);
@phoenix24
phoenix24 / SP14.java
Created December 23, 2018 22:07
java playground - tell me output.
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());
}
@phoenix24
phoenix24 / SP13.java
Created December 23, 2018 22:04
java playground - tell me output?
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() {
@phoenix24
phoenix24 / SP11.java
Created December 23, 2018 21:40
java playground - tell me the output.
public class SP11 {
public synchronized SP11() {
}
public static void main(String[] args) {
System.out.printf("Hello World! Synchronized Constructor!");
}
}
@phoenix24
phoenix24 / SP4.java
Created December 22, 2018 08:52
thread playground - tell me the output.
public class SP4 {
public synchronized void func1() {
System.out.println("func1");
func2();
}
public synchronized void func2() {
System.out.println("func2");
func3();
@phoenix24
phoenix24 / SP10.java
Created December 22, 2018 08:44
thread playground - tell me the output.
public class SP10 {
public static void main(String[] args) {
Thread t = new Thread();
t.start();
t.start();
}
}