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
public class DaemonExample{ | |
public static void main(String[] args) { | |
Thread t = new Thread( | |
()-> { | |
System.out.println("Thread name: "+ Thread.currentThread().getName()); | |
System.out.println("Thread id: "+ Thread.currentThread().getId()); | |
}, "Example_thread"); | |
//sets t2 as daemon thread | |
t.setDaemon(true); |
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
public class TestIsAlive{ | |
public static void main(String[] args) { | |
MyThread m = new MyThread(); | |
System.out.println(m.isAlive()); | |
m.start(); | |
System.out.println(m.isAlive()); | |
try{ | |
m.join(); | |
} catch(Exception 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
class Counter{ | |
int ct = 0; | |
public void increment(){ | |
ct++; //ct = ct+1 | |
} | |
} | |
public class NonSynchronizedCounter { | |
public static void main(String[] args) throws Exception{ |
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
class Counter{ | |
int ct = 0; | |
public synchronized void increment(){ | |
ct++; //ct = ct+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
class Item{ | |
//represent number of item | |
int num; | |
public Item(int num){ | |
this.num = num; | |
} | |
public void put(int num){ | |
System.out.println("Put: "+num); |
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
class Item{ | |
//represent number of item | |
int num; | |
boolean valueSet = false; | |
public Item(int num){ | |
this.num = num; | |
} |
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
250 0 | |
8973 | |
-4625 | |
-2038 | |
3405 | |
-7004 | |
-9853 | |
-361 | |
3294 | |
4036 |
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
#include <functional> | |
#include <queue> | |
#include <vector> | |
#include <iostream> | |
bool cmpa(int l, int r){ | |
return l>r; | |
} | |
template<typename T> void print_queue(T& q) { |
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
#include <unistd.h> | |
#include <string.h> | |
#include <sys/socket.h> | |
#include <arpa/inet.h> | |
#include <iostream> | |
#include <string> | |
#include <fstream> | |
#include <chrono> | |
#include <thread> |
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
# Echo server program | |
import socket | |
HOST = '' # Symbolic name meaning all available interfaces | |
PORT = 3001 # Arbitrary non-privileged port | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind((HOST, PORT)) | |
s.listen(1) | |
conn, addr = s.accept() | |
print ('Connected by', addr) |