Skip to content

Instantly share code, notes, and snippets.

View wkdalsgh192's full-sized avatar
🏠
Working from home

Blue_Avocado wkdalsgh192

🏠
Working from home
View GitHub Profile
python manage.py startapp blog
python manage.py runserver
public class OS_Critical_Section_Solution {
public static void main(String[] args) {
boolean[] flag = new boolean[2]; // flag[0] -> Process A, flag[1] -> Process B
// Strict Alternation
int cnt = 0;
while(true) {
flag[0] = true;
while (flag[1]==true);
System.out.println("V");
package dataStructure;
public class CustomLinkedList<E> {
// Linked List Node
private CustomNode<E> head; // head node
private CustomNode<E> tail; // tail node
private int size;
public int size() {
return size;
import java.util.function.BinaryOperator;
public class MethodReferencesExamples {
public static <T> T mergeThings(T a, T b, BinaryOperator<T> merger) {
return merger.apply(a, b);
}
public static String appendStrings(String a, String b) {return a+b;}
// 1. create a sub class inherent to Thread class
static class MyThread extends Thread {
@Override
public void run() {
System.out.println("Hello : "+Thread.currentThread().getName());
}
}
MyThread myThread = new MyThread();
myThread.start();
Thread thread = new Thread(() -> {
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Thread : "+ Thread.currentThread().getName());
});
Thread newThread = new Thread(() -> {
while (true) {
System.out.println("Thread : "+ Thread.currentThread().getName());
try {
Thread.sleep(2000L);
} catch (InterruptedException e) {
System.out.println("Exit!");
return;
}
}
Thread newThread = new Thread(() -> {
System.out.println("Thread : "+ Thread.currentThread().getName());
try {
Thread.sleep(2000L);
} catch (InterruptedException e) {
System.out.println("Exit!");
return;
}
});
// new single thread created and managed by executor service
ExecutorService executorService = Executors.newSingleThreadExecutor();
Callable<String> hello = () -> {
Thread.sleep(2000L);
return "Hello";
};
Future<String> submit = executorService.submit(hello); // callable object executed and falls asleep for 2 sec
System.out.println(submit.isDone()); // main thread keep running - 1