This file contains 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 com.pivincii; | |
import java.util.concurrent.atomic.AtomicInteger; | |
public class Counter { | |
private AtomicInteger count = new AtomicInteger(0); | |
public void increment() { | |
count.getAndIncrement(); | |
} |
This file contains 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 com.pivincii; | |
import java.util.concurrent.locks.Lock; | |
import java.util.concurrent.locks.ReentrantLock; | |
public class AsynDemo { | |
Lock lock = new ReentrantLock(); | |
public void countTo(int value) { | |
lock.lock(); |
This file contains 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 com.pivincii; | |
public class AsynDemo { | |
synchronized public void countTo(int value) { | |
int count = 0; | |
while (count < value) { | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { |
This file contains 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 com.pivincii; | |
public class AsynDemo { | |
private Object mutex = new Object(); | |
public void countTo(int value) { | |
synchronized (mutex) { | |
int count = 0; | |
while (count < value) { | |
try { |
This file contains 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 com.pivincii; | |
public class AsynDemo { | |
synchronized public void countTo(int value) { | |
int count = 0; | |
while (count < value) { | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { |
This file contains 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 com.pivincii; | |
public class Counter { | |
private int count = 0; | |
public void increment() { | |
count ++; | |
} | |
public void decrement() { |
This file contains 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 com.pivincii; | |
public class Main { | |
public static void main(String[] args) throws InterruptedException { | |
System.out.println("Start Main Thread"); | |
Thread t1 = new Thread(new Runnable() { | |
@Override | |
public void run() { | |
System.out.println("Start Thread 1"); |
This file contains 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 com.pivincii; | |
public class CustomRunnable implements Runnable { | |
@Override | |
public void run() { | |
System.out.println("Start " + Thread.currentThread().getName()); | |
try { | |
Thread.sleep(5000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); |
This file contains 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 com.pivincii; | |
public class FirstThread extends Thread { | |
public void run() { | |
try { | |
System.out.println("Start " + currentThread().getName()); | |
sleep(5000); | |
System.out.println("End" + currentThread().getName()); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); |
This file contains 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 com.pivincii.blogging | |
import android.os.Bundle | |
class MainActivity : ActivityResultObservableActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
} |